atcoder#ABC223D. [ABC223D] Restricted Permutation

[ABC223D] Restricted Permutation

Score : 400400 points

Problem Statement

Among the sequences PP that are permutations of (1,2,,N)(1, 2, \dots, N) and satisfy the condition below, find the lexicographically smallest sequence.

  • For each i=1,,Mi = 1, \dots, M, AiA_i appears earlier than BiB_i in PP.

If there is no such PP, print -1.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1M2×1051 \leq M \leq 2 \times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • AiBiA_i \neq B_i
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

A1A_1 B1B_1

\vdots

AMA_M BMB_M

Output

Print the answer.

4 3
2 1
3 4
2 4
2 1 3 4

The following five permutations PP satisfy the condition: $(2, 1, 3, 4), (2, 3, 1, 4), (2, 3, 4, 1), (3, 2, 1, 4), (3, 2, 4, 1)$. The lexicographically smallest among them is (2,1,3,4)(2, 1, 3, 4).

2 3
1 2
1 2
2 1
-1

No permutations PP satisfy the condition.