#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > c(m);
  for (int i = 0; i < m; i++) {
    cin >> c[i].first >> c[i].second;
    c[i].first--;
    c[i].second--;
  }
  int l = 0, r = m + 1, d;
  while (l < r - 1) {
    int d = (l + r) / 2;
    vector<vector<int> > e(n), re(n);
    for (int i = 0; i < d; i++) {
      e[c[i].first].push_back(c[i].second);
      re[c[i].second].push_back(c[i].first);
    }
    vector<int> cnt(n);
    for (int i = 0; i < n; i++) cnt[i] = e[i].size();
    int flag = 1;
    vector<int> suspects;
    for (int i = 0; i < n; i++)
      if (cnt[i] == 0) suspects.push_back(i);
    for (int i = 0; i < n; i++) {
      if (suspects.size() != 1) {
        flag = 0;
        break;
      }
      int susp = suspects[0];
      suspects.pop_back();
      for (auto x : re[susp]) {
        cnt[x]--;
        if (cnt[x] == 0) suspects.push_back(x);
      }
    }
    if (flag)
      r = d;
    else
      l = d;
  }
  if (r == m + 1)
    cout << -1;
  else
    cout << r;
}
