#include <bits/stdc++.h>
using namespace std;
bool check_one(const vector<vector<int>> &g) {
  int n = (int)(g).size();
  vector<int> in_deg(n);
  for (int i = 0; i < n; i++)
    for (int x : g[i]) in_deg[x]++;
  set<pair<int, int>> who;
  for (int i = 0; i < n; i++) who.insert(make_pair(in_deg[i], i));
  for (int it = 0; it < n; it++) {
    assert((int)(who).size() == n - it);
    if ((int)(who).size() == 1) return true;
    int ver = who.begin()->second;
    assert(who.begin()->first == 0);
    who.erase(who.begin());
    assert(!who.empty());
    if (who.begin()->first == 0) return false;
    for (int dest : g[ver]) {
      who.erase(make_pair(in_deg[dest], dest));
      in_deg[dest]--;
      who.insert(make_pair(in_deg[dest], dest));
    }
  }
  assert(false);
  return false;
}
void solve(int n) {
  int m;
  cin >> m;
  vector<pair<int, int>> e(m);
  for (int i = 0; i < m; i++)
    cin >> e[i].first >> e[i].second, e[i].first--, e[i].second--;
  auto go_check = [&](int what) -> bool {
    assert(0 <= what && what <= m);
    vector<vector<int>> g(n);
    for (int i = 0; i < what; i++) {
      int x = e[i].first, y = e[i].second;
      g[x].push_back(y);
    }
    return check_one(g);
  };
  if (!go_check(m)) {
    cout << -1 << endl;
    return;
  }
  int left = 0, right = m;
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (go_check(mid))
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) solve(n);
}
