from collections import deque def scc(x,y,n): res=[-1]*n p=0 a=[0]*n;b=[0]*n for i in range(n): if b[i]: continue b[i]=1 f=deque([(i,0)]) while f: q,w=f.pop() if len(x[q])>w: f.append((q,w+1)) if b[x[q][w]]: continue f.append((x[q][w],0)) b[x[q][w]]=1 else: a[p]=q;p+=1 for i in reversed(a): if res[i]!=-1: continue f=deque([i]);res[i]=i while f: q=f.pop() for j in y[q]: if res[j]==-1: f.append(j);res[j]=i return res n,q=map(int,input().split()) v=[tuple(map(lambda x:int(x)-1,input().split())) for i in range(q)] a,b=0,q while b-a>1: m=(a+b)//2 x=[[] for i in range(n)] y=[[] for i in range(n)] for i in range(m+1): x[v[i][0]].append(v[i][1]) y[v[i][1]].append(v[i][0]) c=scc(x,y,n) for i in range(n): if i!=c[i]: b=m;break else : a=m if b==q: b=-2 print(b+1)