14751475 SUSTech Online Judge
Problem 1475 --Connect all cities

1475: Connect all cities

Time Limit: 1 Sec  Memory Limit: 1024 MB
Submit: 909  Solved: 198
[Submit][Status][Web Board]

Description

There are n cities and m roads, each road is unidirectional. Sinzo wants to build some roads, to make each city can reach other cities. Please tell how many roads should Sinzo construct at least?


Input

The first line contains two integers, n, m \((1\leq n, m\leq 10^5)\), indicating the number of cities and the number of roads. 

The next m lines, each line contains two integers u, v, indicating there is a unidirectional road from u to v.

Output

Please output the number of roads to construct in one line.


Sample Input

4 4
1 2
2 3
3 1
3 4

Sample Output

1

HINT

Source

 

[Submit][Status]