#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, rev;
vector<pair<int, int> > edg;
int n, m;
bool check(int k) {
  g.clear();
  g.resize(n);
  rev = g;
  for (int i = 0; i < k; i++) {
    g[edg[i].first].push_back(edg[i].second);
    rev[edg[i].second].push_back(edg[i].first);
  }
  for (int i = 0; i < n; i++) sort(rev[i].begin(), rev[i].end());
  vector<int> lev(n, 0);
  priority_queue<pair<int, int> > q;
  for (int i = 0; i < n; i++) {
    if (!rev[i].size()) q.push({0, i});
  }
  while (q.size()) {
    int i = q.top().second, l = -q.top().first;
    q.pop();
    lev[i] = max(lev[i], l);
    for (int j = 0; j < g[i].size(); j++) {
      rev[g[i][j]].erase(
          lower_bound(rev[g[i][j]].begin(), rev[g[i][j]].end(), i));
      if (!rev[g[i][j]].size()) q.push({-lev[i] - 1, g[i][j]});
    }
  }
  sort(lev.begin(), lev.end());
  lev.erase(unique(lev.begin(), lev.end()), lev.end());
  return lev.size() == n;
}
int main() {
  while (cin >> n >> m) {
    edg.resize(m);
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &edg[i].first, &edg[i].second);
      ;
      edg[i].first--;
      edg[i].second--;
    }
    int res = -1;
    int low = 1, high = m, mid;
    while (low <= high) {
      mid = (high + low) / 2;
      if (check(mid))
        res = mid, high = mid - 1;
      else
        low = mid + 1;
    }
    cout << res << endl;
  }
  return 0;
}
