시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB75571.429%

문제

The president of Nlogonia decided, by decree, that all the streets of Nlogonia should be one-way. Due to the lack of knowledge of elementary science, there was no proper planning for the changes. After the new system came in place, people would not be able to go to work, or would not be able to return home from work, for example. As a result, there was chaos and riots in lots of cities.

The president was impeached and the new administration of the country hired a team of scientists to solve the problem. In turn, the committee hired you, an expert in complexity of algorithms, to help them with the efficient computation of solutions.

So, for each city, you are given the reference points of the city, and the one-way streets, each of which connects two reference points. Your task is to determine the minimum number of one-way bridges that must be built in order to have full connectivity in the city. Each bridge should also connect two reference points.

입력

The first line of the input contains two integers, $N$ and $M$ ($1 ≤ N ≤ 10^4$, $1 ≤ M ≤ 10^6$), where $N$ is the number of reference points and $M$ is the number of streets. Each one of the next $M$ lines contains two integers, $R$ and $S$, $1 ≤ R, S ≤ N$, $R \ne S$, that corresponds to a street connecting $R$ to $S$, so that every vehicle in that street must move away from $R$, towards $S$.

출력

Your program must print a single line containing the minimum number of bridges that are necessary to make the inhabitants happy.

예제 입력 1

7 7
1 2
2 3
3 1
6 1
6 4
4 5
7 6

예제 출력 1

2

예제 입력 2

7 7
2 1
3 2
1 3
1 6
4 6
5 4
6 7

예제 출력 2

2

예제 입력 3

2 1
1 2

예제 출력 3

1

예제 입력 4

3 3
1 2
2 3
3 1

예제 출력 4

0

예제 입력 5

2 0

예제 출력 5

2

예제 입력 6

6 4
1 2
1 3
4 6
5 6

예제 출력 6

3