#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



const int MAX_V = 100100;
const int MAX_E = 200200;

struct Graph {
    int V,E;
    vector<pint> list[MAX_V];
    vector<int> back[MAX_V];
    
    Graph(int n = 0) : V(n), E(0) {}
    void init(int n = 0) {V = n; E = 0; for (int i = 0; i < MAX_V; ++i) {list[i].clear(); back[i].clear();} }
    inline vector<pint>& operator [] (int i) {return list[i];}
    
    void direct(int f, int t, int num) {
        ++E;
        list[f].push_back(MP(t,num));
        back[t].push_back(f);
    }
} G; 

ostream& operator << (ostream& s, const Graph& G) {
    for (int i = 0; i < G.V; ++i) {s << i << " : " << G.list[i];}
    return s;
}

int n, m;
int a, b;
int s, t;

int dist1[MAX_V];
int dist2[MAX_V];

int rec1(int v) {
    if (dist1[v] != -1) return dist1[v];
    if (v == t) return 0;
    int res = -1;
    for (int i = 0; i < G[v].size(); ++i) {
        int to = G[v][i].FI;
        int dep = rec1(to) + 1;
        res = max(res, dep);
    }
    //cout << "1 " << v << " : " << res << endl;
    return dist1[v] = res;
}

int rec2(int v) {
    if (dist2[v] != -1) return dist2[v];
    if (v == s) return 0;
    int res = -1;
    for (int i = 0; i < G.back[v].size(); ++i) {
        int to = G.back[v][i];
        int dep = rec2(to) + 1;
        res = max(res, dep);
    }
    //cout << "2 " << v << " : " << res << endl;
    return dist2[v] = res;
}

vector<int> num[MAX_V];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> n >> m) {
        G.init(n+2);
        s = 0, t = n+1;
        int id = 1;
        for (int i = 0; i < m; ++i) {
            scanf("%d %d", &a, &b);
            G.direct(a, b, id); ++id;
        }
        for (int i = 1; i <= n; ++i) {G.direct(s, i, 0);}
        for (int i = 1; i <= n; ++i) {G.direct(i, t, 0);}
        
        //COUT(G);
        
        memset(dist1, -1, sizeof(dist1));
        memset(dist2, -1, sizeof(dist2));
        int len = rec1(s);
        rec2(t);
        
        for (int i = 0; i < MAX_V; ++i) num[i].clear();
        for (int i = 1; i <= n; ++i) {
            for (int j = 0; j < G[i].size(); ++j) {
                int from = i, to = G[i][j].FI, id = G[i][j].SE;
                if (dist1[from] == dist1[to] + 1 && dist2[to] == dist2[from] + 1 
                    && dist1[to] + dist2[to] == len) {
                    num[dist1[to]].PB(id);
                }
            }
        }
        
        vint res;
        for (int i = 0; i <= n; ++i) {
            //cout << i << " : " << num[i];
            if (num[i].size() == 1) res.PB(num[i][0]);
        }
        sort(ALL(res));
        
        for (int i = 0; i < res.size(); ++i) cout << res[i] << endl;
        if (res.size() == 0) cout << -1 << endl;
    }
    
    return 0;
}
