#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Edge{
  int dst, index;
  bool b;
  Edge(int d) : dst(d) {}
  Edge(int d, int idx) : dst(d), index(idx), b(false) {}
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;
void update(int& x, int y){ if(x < y) x = y; }

int main(){
  int N, M;
  while(cin >> N >> M){
    Graph G(N);
    Graph G_inv(N);
    REP(i, M){
      int a, b; cin >> a >> b;
      a--; b--;
      G[a].push_back(Edge(b, i + 1));
      G_inv[b].push_back(Edge(a, i + 1));
    }
    vector<int> dp(N);
    REP(u, N){
      FORIT(e, G[u]){
        update(dp[e->dst], dp[u] + 1);
      }
    }
    int max_height = 0;
    REP(i, N) update(max_height, dp[i]);
    vector<bool> use(N);
    REP(i, N) if(max_height == dp[i]) use[i] = true;
    map<int, int> m;
    for(int i = N - 1; i >= 0; i--)if(use[i]){
      FORIT(e, G_inv[i]){
        if(dp[e->dst] + 1 == dp[i]){
          e->b = true;
          m[dp[e->dst]]++;
          use[e->dst] = true;
        }
      }
    }
    vector<int> ans;
    REP(i, N)FORIT(e, G_inv[i])if(e->b && m[dp[e->dst]] == 1){
      ans.push_back(e->index);
    }
    sort(ans.begin(), ans.end());
    if(ans.empty()){
      cout << -1 << endl;
    }else{
      REP(i, ans.size()) cout << ans[i] << endl;
    }
  }
  return 0;
}