CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #959 #961 →

#960. Topological sort

You get n tasks and m rules `u v` (u must be done before v); there are no cycles. Of all possible orders, print the lexicographically smallest one. ### Input n m, then m lines. ### Output One line.

Examples

Input
5 4
3 2
3 4
3 5
4 5
Output
1 3 2 4 5
Input
6 0
Output
1 2 3 4 5 6

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!