Condensation of the graph#511

Condensation of the graph

2 seconds
128 megabytes
Medium (≈1350)

Find the number of edges in the condensation of a given directed graph.

The condensation of a directed graph is a directed graph G', whose vertices are strongly connected components of , and the edge in G' is present only if there exists at least one edge between the vertices of corresponding connected components.

The graph condensation does not contain multiple edges.

Input

The first line contains number of vertices and number of edges m~(n \le 10^4, m \le 10^5) in the graph. Each of the next lines describe the edge of the graph. The -th edge is given with the starting b_i and the ending e_i~(1 \le b_i, e_i \le n) vertex of the graph. The input graph can contain the multiple edges and loops.

Output

Print the number of edges in graph condensation.

Examples

Example 1

Loading
Loading