Kahn Algorithm

medium
1. You are given a directed acyclic graph. The vertices represent tasks and edges represent 
    dependencies between tasks.
2. You are required to find and print the order in which tasks could be done. The task that should be 
    done at last should be printed first and the task which should be done first should be printed last. 
    This is called topological sort. 

Input Format

First line contains number of vertices V. Second line contains number of edges E. Each of next E lines contain 2 number u and v denoting an edge u to v.

Output Format

For each test case print topological order of the graph.

Constraints

1 <= v <= 1000
1 <= E <= v*(v-1)/2

Example

Input
7
7
0 1
1 2
2 3
0 3
4 5
5 6
4 6
Output
0
4
1
5
2
6
3
Previous
Guess Number Higher Or Lower
Next
Maximum Length Of Repeated Subarray

Related Questions