Gluing
An oriented graph is provided, with vertices numbered from 1 to N. In this graph, you can perform an operation that merges two vertices. This operation involves removing the two vertices and adding a new vertex. The new vertex inherits incoming edges from any vertex that had edges to at least one of the removed vertices, and it sends outgoing edges to all vertices that at least one of the removed vertices had edges to. The new vertex is assigned the smallest number of the merged vertices. Your task is to determine the minimum number of merging operations required so that it becomes possible to reach any vertex from any other vertex in the graph.
Input Data The first line of the input contains the integers N and M — the number of vertices and edges in the graph (1 ≤ N ≤ 200). The following M lines describe the edges, each specified by the starting and ending vertex numbers. The graph does not contain loops or multiple edges. Output Data Output K — the number of merging operations needed.