Starting from:

$30

Making Felix Felicis

Making Felix Felicis
Hermione is currently working on an assignment for making the Felix Felicis potion as it is a good idea to
have good luck when they are searching for the Horcruxes. The only problem is that this is a very complex
potion to make. She wants to speed it up by splitting the potion into multiple parts where each part can
be done separately and independently. Unfortunately even though she has managed to figure out these
parts she does need to mix them up at some point to get all the intermediate concoctions.
Help Hermione get the best way for making the potion.
Input Format
The first line contains two numbers the number of stages of the potion and relations for making the
stages, respectively.
The next lines contain two numbers denoting a relation between the two stages of the
potion, which means that to make the 'th stage of the potion Hermione needs the 'th stage to be
completed.
Constraints
Output Format
Print the stages in order of completion in a single line separated by a single space.
If there are multiple ways you can complete the potion then print the one which is smallest in the lexical
order. If Hermione has not made the correct stages and there is no way to complete the potion then print
"-1" without the quotes.
Sample Input 0
5 10
5 1
2 3
4 3
5 3
2 1
4 1
5 2
1 3
4 2
5 4
Sample Output 0
5 4 2 1 3
Sample Input 1
4 6
3 2
1 2
1 3
1 4
3 4
4 2
Sample Output 1
1 3 4 2
Sample Input 2
5 10
4 2
3 2
1 5
4 3
1 2
3 5
2 5
1 4
4 5
3 1
Sample Output 2
-1

More products