Helping the Transit

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

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, NN and MM (1N1041 ≤ N ≤ 10^4, 1M1061 ≤ M ≤ 10^6), where NN is the number of reference points and MM is the number of streets. Each one of the next MM lines contains two integers, RR and SS, 1R,SN1 ≤ R, S ≤ N, RSR \ne S, that corresponds to a street connecting RR to SS, so that every vehicle in that street must move away from RR, towards SS.

출력

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