from collections import deque n,q=map(int,input().split()) ab=[] for _ in range(q): a,b=map(int,input().split()) a-=1;b-=1 ab.append((a,b)) def check(x): deg=[0]*n g=[[] for _ in range(n)] q=deque() for a,b in ab[:x]: deg[b]+=1 g[a].append(b) for i in range(n): if deg[i]==0: q.append(i) ans=[] while q: now=q.popleft() ans.append(now) for to in g[now]: deg[to]-=1 if deg[to]==0: q.append(to) return len(ans)!=n r=q+1;l=0 while r-l>1: mid=(r+l)//2 if check(mid): r=mid else: l=mid if r>q: print(-1) else: print(r)