Kosaraju Algorithm

hard
You are given a graph with N nodes and M directed edges. Find the number of Strongly connected components in the graph.

Input Format

First line contains two space separated integers,N and M. Then M lines follow, each line has 2 space separated integers ai and bi.

Output Format

Print in one line the number of strongly connected components in the graph.

Constraints

1<= N <= 10000
1<= M <= (N*(N-1))/2
1<= ai, bi <= N

Example

Input
5 6
1 4
1 3
2 4
3 4
4 5
5 1
Output
2
Previous
Pepcoding Course Schedule
Next
Mother Vertex

Related Questions