Problem list
Log in
#r03244 · Online Judge > GoldOJ

Main Quest

Gold III 2.0 s 1024 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code