Time limit
2s
Memory limit
128 MB
There are N students, and they must be lined up in an order consistent with their heights. Measuring every student's height and sorting them directly would be simple, but only some pairwise comparisons are available.
Each comparison tells which of two students must stand earlier in the line. Given all available comparisons, write a program that outputs an order of the students that satisfies every comparison.
The first line contains N (1 <= N <= 32,000) and M (1 <= M <= 100,000), where M is the number of comparisons.
Each of the next M lines contains two student numbers A and B. This means student A must stand before student B.
Students are numbered from 1 to N.
Print the student numbers in order from the front of the line, separated by spaces.
If more than one valid order exists, print any one of them.