#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < (int)(m); i++) cin >> a[i] >> b[i], a[i]--, b[i]--;
  vector<int> c[n], q;
  int deg[n];
  function<int(int)> check = [&](int k) {
    for (int i = 0; i < (int)(n); i++) c[i].clear(), deg[i] = 0;
    for (int i = 0; i < (int)(k); i++) c[a[i]].push_back(b[i]), deg[b[i]]++;
    q.clear();
    for (int i = 0; i < (int)(n); i++)
      if (!deg[i]) q.push_back(i);
    for (int i = 0; i < (int)(n); i++) {
      if (q.size() != i + 1) return 0;
      int x = q[i];
      for (int y : c[x])
        if (!--deg[y]) q.push_back(y);
    }
    return 1;
  };
  if (!check(m)) {
    puts("-1");
    return 0;
  }
  int l = 0, r = m;
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
}
