import sys sys.setrecursionlimit(10 ** 9) import pypyjit pypyjit.set_param('max_unroll_recursion=-1') n, q = map(int, input().split()) edges = [[] for _ in range(n)] for i in range(1, q + 1): a, b = map(int, input().split()) edges[a - 1].append((b - 1, i)) used = [False] * n used2 = [False] * n def dfs(pos, x): used2[pos] = True for npos, i in edges[pos]: if i > x: continue if used2[npos]: return True if used[npos]: continue used[npos] = True if dfs(npos, x): return True used2[pos] = False return False def ok(x): global used, used2 used = [False] * n used2 = [False] * n for i in range(n): if used[i]: continue used[i] = True if dfs(i, x): return True return False l = 0 r = q + 1 while r - l > 1: mid = (l + r) // 2 if ok(mid): r = mid else: l = mid if r == q + 1: print(-1) else: print(r)