{"problem":{"name":"Restricted Permutation","description":{"content":"Among the sequences $P$ that are permutations of $(1, 2, \\dots, N)$ and satisfy the condition below, find the lexicographically smallest sequence. *   For each $i = 1, \\dots, M$, $A_i$ appears earlie","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc223_d"},"statements":[{"statement_type":"Markdown","content":"Among the sequences $P$ that are permutations of $(1, 2, \\dots, N)$ and satisfy the condition below, find the lexicographically smallest sequence.\n\n*   For each $i = 1, \\dots, M$, $A_i$ appears earlier than $B_i$ in $P$.\n\nIf there is no such $P$, print `-1`.\n\n## Constraints\n\n*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq M \\leq 2 \\times 10^5$\n*   $1 \\leq A_i, B_i \\leq N$\n*   $A_i \\neq B_i$\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$\n$A_1$ $B_1$\n$\\vdots$\n$A_M$ $B_M$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc223_d","tags":[],"sample_group":[["4 3\n2 1\n3 4\n2 4","2 1 3 4\n\nThe following five permutations $P$ 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 3\n1 2\n1 2\n2 1","\\-1\n\nNo permutations $P$ satisfy the condition."]],"created_at":"2026-03-03 11:01:13"}}