#include <bits/stdc++.h>
using namespace std;
vector<vector<long> > g;
vector<long> v, ans;
set<long> used, q;
void bfs() {
  long vrt;
  while (q.size() == 1) {
    vrt = *q.begin();
    q.erase(q.begin());
    ans.push_back(vrt);
    used.insert(vrt);
    for (long i = 0; i < g[vrt].size(); ++i) {
      --v[g[vrt][i]];
      if (v[g[vrt][i]] == 0) q.insert(g[vrt][i]);
    }
  }
}
int main() {
  long n, m;
  scanf("%ld %ld", &n, &m);
  g.resize(n + 1);
  v.resize(n + 1, 0);
  for (long i = 1; i <= n; ++i) q.insert(i);
  long a, b, isAns = -1;
  for (long i = 0; i < m; ++i) {
    scanf("%ld %ld", &a, &b);
    if (v[b] == 0) {
      if (used.find(a) == used.end()) {
        q.erase(b);
        g[a].push_back(b);
        ++v[b];
      }
      if (q.size() == 1) bfs();
    } else if (used.find(a) == used.end()) {
      g[a].push_back(b);
      ++v[b];
    }
    if (ans.size() == n) {
      isAns = i + 1;
      break;
    }
  }
  printf("%ld\n", isAns);
  return 0;
}
