#include <bits/stdc++.h>
using namespace std;
const int N = 212345, LG = 21, mod = 1000000007;
const double eps = 1e-3, pi = acos(-1.0);
int in[N];
vector<int> adj[N];
map<pair<int, int>, int> mp;
set<pair<int, int>> s;
int main() {
  int n, m;
  scanf("%d", &n), scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d", &u), scanf("%d", &v);
    adj[u].push_back(v);
    mp[{u, v}] = i;
    in[v]++;
  }
  for (int i = 1; i <= n; ++i) s.insert({in[i], i});
  int ans = -1;
  while (s.size() > 1) {
    int t = s.begin()->second;
    s.erase(s.begin());
    if (in[t] != 0) {
      ans = -1;
      break;
    }
    if (s.begin()->first == 0) {
      ans = -1;
      break;
    }
    for (int i = 0; i < adj[t].size(); ++i) {
      int u = adj[t][i];
      s.erase({in[u], u});
      in[u]--;
      s.insert({in[u], u});
    }
    ans = max(ans, mp[{t, s.begin()->second}]);
  }
  printf("%d\n", ans);
  return 0;
}
