from sys import setrecursionlimit from pypyjit import set_param setrecursionlimit(10 ** 6) set_param("max_unroll_recursion=-1") def DFS(v): seen[v] = 1 for i in g[v]: if seen[i] == 1 or (seen[i] == 0 and DFS(i)): return True seen[v] = 2 return False n, q = map(int, input().split()) edges = [] for i in range(q): a, b = map(int, input().split()) edges.append((a-1, b-1)) left, right = -1, q + 1 while abs(left - right) > 1: mid = (right + left) // 2 g = [[] for _ in range(n)] for a, b in edges[:mid]: g[a].append(b) seen = [0] * n has_cycle = False for i in range(n): if seen[i] == 0 and DFS(i): has_cycle = True if has_cycle: right = mid else: left = mid ans = right print(ans if ans != q + 1 else -1)