/*input
3 2
1 2
3 2
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PII pair<ll, ll>
#define f first
#define s second
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define inf LLONG_MAX
#define mod 1000000007
#define MAXN 100005
#define pb(x) push_back(x)
ll n, m, u, v, ind=1, ans;
vector<bool> vis;
vector<vector<ll> > g;
PII arr[MAXN];
map < PII, ll > mp;
stack < ll > st;
ll tmp[MAXN];
void dfs1(ll u)
{
ll sz=g[u].size();
vis[u]=1;
F(v,0,sz-1)
if(!vis[g[u][v]])
dfs1(g[u][v]);
st.push(u);
}
void dfs2(ll u)
{
tmp[ind++]=u;
vis[u]=1;
ll sz=g[u].size();
F(v,0,sz-1)
if(!vis[g[u][v]])
dfs2(g[u][v]);
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
g = vector<vector<ll> > (n+1); //initialization of the graph
vis = vector<bool> (n+1, 0); // initially mark all vertices as unvisited
F(i,1,m)
{
cin>>u>>v;
g[u].pb(v);
mp[{u,v}]=i;
}
F(i,1,n)
{
if(!vis[i])
dfs1(i);
}
vis = vector<bool> (n+1, 0); // initially mark all vertices as unvisited
while(!st.empty())
{
ll cur=st.top();
st.pop();
if(!vis[cur])
dfs2(cur);
}
PII cur;
bool flag=1;
F(i,1,n-1)
{
cur.f=tmp[i];
cur.s=tmp[i+1];
if(mp[cur]==0)
{
flag=0;
break;
}
ans=max(ans,mp[cur]);
}
if(flag)
cout<<ans<<endl;
else
cout<<"-1"<<endl;
return 0;
}
LyppbnB1dAozIDIKMSAyCjMgMgoqLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIFBJSSBwYWlyPGxsLCBsbD4KI2RlZmluZSBmIGZpcnN0CiNkZWZpbmUgc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