from sys import setrecursionlimit setrecursionlimit(10 ** 6) def DFS(v, g, seen): seen[v] = 1 for i in g[v]: if seen[i] == 1 or (seen[i] == 0 and DFS(i, g, seen)): return True seen[v] = 2 return False if __name__ == '__main__': 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, g, seen): has_cycle = True if has_cycle: right = mid else: left = mid ans = right if ans==q+1: ans=-1 print(ans)