12580 - Chain of Ancestors   

Description

You are being reported about some relations in the form "x is the parent of y".

It is safe to assume that there will not be cycle relations (e.g., x is parent of y, y is parent of z, z is parent of x).

You are now curious about the maximum number of people you can choose, such that every person but one is the parent of exactly one other person (among those you chose), and every person but one is parented by exactly one other person (among those you chose).

Input

N M

X_1 Y_1

X_2 Y_2

...

X_M Y_M

 

(N and M are positive integers not exceeding 1000000, and X_i, Y_i are integers between 1 and N, it is guaranteed that no circular relationships will occur)

(X_i Y_i means X_i is the parent of Y_i)

Output

The desired output as an integer, followed by a newline character

Sample Input  Download

Sample Output  Download

Tags




Discuss