Reverse the graph#10048

Reverse the graph

6 seconds
256 megabytes
Very easy

A directed graph with vertices and edges is given, with vertices numbered from to . Find the minimum number of edges that need to be reversed so that there exists at least one path from vertex to vertex .

Input

The first line contains two integers and m~(1 \le n, m \le 2 \cdot 10^6) — the number of vertices and edges in the graph. Each of the following lines contains two integers x_i and y_i~(1 \le x_i, y_i \le n), indicating that the -th directed edge goes from vertex x_i to vertex y_i.

Output

Print the minimum number of edges that need to be reversed. If it is not possible to obtain a path from vertex to vertex , print .

Examples

Example 1

Loading
Loading