import sys input = sys.stdin.readline from collections import deque N,Q=map(int,input().split()) AB=[list(map(lambda x:int(x)-1,input().split())) for _ in range(Q)] from collections import defaultdict,deque def check_cycle(n): ins = defaultdict(int) outs = defaultdict(list) for a,b in AB[:n]: ins[b]+=1 outs[a].append(b) res = [] que = deque([i for i in range(N) if ins[i] == 0]) while que: v = que.popleft() res.append(v) for v2 in outs[v]: ins[v2] -= 1 if ins[v2] == 0: que.append(v2) if len(res) != N: return True # 閉路検出 return False def solve(): if not check_cycle(N): print(-1) return ng,ok = 0,Q while ng+1