There are $N$ quests with $M$ prerequisite relations A B meaning quest $A$ must be cleared before quest $B$. Clear all quests, always choosing the smallest-numbered quest currently available. Print the clearing order, space-separated, or -1 if it is impossible to clear them all.
Input
Line 1: $N$ $M$. Next $M$ lines: A B.
Output
Print the quest order, or -1.
Example 1
Input
4 2 4 2 3 1
Output
3 1 4 2
Example 2
Input
3 3 1 2 2 3 3 1
Output
-1
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.