#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  run();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v(m);
  for (auto &it : v) cin >> it.first >> it.second;
  auto valid = [&](int k) {
    vector<vector<int>> adj(n + 1);
    vector<int> in(n + 1);
    for (int i = 0; i < k; i++) {
      adj[v[i].first].push_back(v[i].second);
      in[v[i].second]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++)
      if (in[i] == 0) q.push(i);
    while ((int)(q.size())) {
      if ((int)(q.size()) != 1) return false;
      int cur = q.front();
      q.pop();
      for (int ch : adj[cur])
        if (--in[ch] == 0) q.push(ch);
    }
    for (int i = 1; i <= n; i++)
      if (in[i] != 0) return false;
    return true;
  };
  int st = 1, ed = m, ans = -1;
  while (st <= ed) {
    int md = st + ed >> 1;
    if (valid(md))
      ed = md - 1, ans = md;
    else
      st = md + 1;
  }
  cout << ans << "\n";
}
