#C8246. Infected Servers

    ID: 52207 Type: Default 1000ms 256MiB

Infected Servers

Infected Servers

You are given a network of N servers labeled from 1 to N and M operations describing one-way connections between servers. Initially, only server 1 is infected with malware. An operation represented by a pair \( (a, b) \) indicates that if server \( a \) is infected, it can directly infect server \( b \).

Your task is to determine how many servers become infected when the malware spreads through the network starting from server 1. In other words, count the number of servers that are reachable from server 1 in the directed graph.

Note: The infection can only spread in the direction given by the operations.

inputFormat

The input consists of multiple datasets. Each dataset begins with a line containing two integers N and M, where N is the number of servers and M is the number of operations. This is followed by M lines, each containing two integers \( a \) and \( b \), representing a directed connection from server \( a \) to server \( b \). The input terminates with a line where both N and M are 0 (i.e. "0 0").

outputFormat

For each dataset, print a single line containing the number of servers that become infected (i.e. the number of servers reachable from server 1).

## sample
4 3
1 2
2 3
3 4
0 0
4

</p>