#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int n,m;
vector<pi> G[100010];
int dp[100010];
int used[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>n>>m;
	int a,b;
	rep(i,m){
		cin>>a>>b;
		a--,b--;
		G[b].pb(mp(a,i+1));
	}
	int M=0;
	rep(i,n){
		rep(j,sz(G[i])){
			dp[i]=max(dp[i],dp[G[i][j].fir]+1);
		}
		M=max(M,dp[i]);
	}
	vi v,w,ans;
	rep(i,n)if(dp[i]==M)v.pb(i);
	while(dp[v[0]]){
		//rep(i,sz(v))cout<<v[i]<<" ";cout<<endl;
		w.clear();
		rep(i,sz(v)){
			rep(j,sz(G[v[i]])){
				if(!used[G[v[i]][j].fir] && dp[G[v[i]][j].fir] == dp[v[i]]-1){
					w.pb(G[v[i]][j].fir);
					used[G[v[i]][j].fir]=1;
				}
			}
		}
		if(sz(v)==1 && sz(w)==1){
			rep(i,sz(G[v[0]])){
				if(dp[G[v[0]][i].fir] == dp[v[0]]-1){
					ans.pb(G[v[0]][i].sec);
				}
			}
		}
		v=w;
	}
	sort(ans.begin(),ans.end());
	if(sz(ans)==0)cout<<-1<<endl;
	else rep(i,sz(ans))cout<<ans[i]<<endl;
}