Pepcoding Course Schedule
easy
Pepcoding offers total of n courses labelled from 0 to n-1. Some courses may have prerequisites. you have been given m pairs ai,bi. where 1 pair means you must take the course bi before the course ai. Given the total number of courses numCourses and a list of the prerequisite pairs, return the ordering of courses you should take to finish all courses. If it is impossible to finish all courses print -1.
Constraints
1 <= numCourses <= 2000 0 <= ai, bi < numCourses ai != bi All the pairs ai,bi are distinct.
Format
Input
first line contains 2 numbers n,m wher n represents number of course and m is number of pairs representing prerequisite. Then m lines follow, each line has 2 space separated integers ai , bi.
Output
Print the ordering of courses you should take to finish all courses.Print the ordering of courses you should take to finish all courses.
Example
Sample Input
4 4
1 0
2 0
3 1
3 2
Sample Output
0 1 2 3