Gluing#189

Gluing

3 seconds
64 megabytes
Hard

Given a directed graph with vertices numbered from to . You may perform an operation called merging: remove two vertices from the graph and add one new vertex. This new vertex receives incoming arcs from all vertices that had arcs to at least one of the removed vertices, and it sends outgoing arcs to all vertices to which at least one of the removed vertices had arcs. The new vertex takes the smallest number of the merged vertices as its number.

Determine the minimum number of merging operations required to make the graph strongly connected, that is, so that from any vertex it is possible to reach any other vertex.

Input

The first line contains two integers and (1 \leq N \leq 200) — the number of vertices and the number of arcs. The next lines each contain two integers specifying the starting and ending vertices of an arc. The graph contains no loops and no multiple arcs.

Output

Output a single integer — the minimum number of merging operations required.

Examples

Example 1

Loading
Loading