#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<pair<int, int> > > graph(n);
vector<int> dp;
vector<int> res;
int check(int v) {
  if (dp[v]) {
    return dp[v];
  }
  dp[v] = 1;
  for (int i = 0; i < graph[v].size(); i++) {
    int neigh = graph[v][i].first;
    int num = graph[v][i].second;
    if (check(neigh) + 1 > dp[v]) {
      dp[v] = dp[neigh] + 1;
      res[v] = max(res[neigh], num);
    }
  }
  return dp[v];
}
int main() {
  int n, m;
  cin >> n >> m;
  graph.resize(n);
  dp.resize(n);
  res.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(make_pair(b, i));
  }
  for (int i = 0; i < n; i++) {
    if (check(i) == n) {
      cout << res[i] + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
