Condensation of the graph#1947

Condensation of the graph

2 seconds
128 megabytes
Very easy

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

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

There are no multiple edges in the condensation graph.

Input

The first line contains the number of vertices and the number of edges m~(n \le 10^4, m \le 10^5) in the graph. Each of the next lines describes one edge of the graph. The -th edge is given by two numbers: the starting vertex b_i and the ending vertex e_i~(1 \le b_i, e_i \le n). The original graph may contain multiple edges and self-loops.

Output

Print the number of edges in the condensation graph.

Examples

Example 1

Loading
Loading