#include <bits/stdc++.h>
using namespace std;
int n, m, fim[100050], grau[100050], dp[100050], d[100050];
vector<int> grafo[100050], aux[100050], lista;
vector<pair<int, int> > edge;
int processed2[100050];
bool verif2() {
  for (int i = 1; i <= n; i++) {
    if (processed2[d[i]]) return false;
    processed2[d[i]] = 1;
  }
  return true;
}
bool solve(int k) {
  memset(grau, 0, sizeof grau);
  memset(d, 0, sizeof d);
  for (int i = 1; i <= n; i++) aux[i].clear();
  deque<int> lista;
  for (int i = 0; i < k; i++) {
    int a = edge[i].first, b = edge[i].second;
    aux[a].push_back(b);
    grau[b]++;
  }
  for (int i = 1; i <= n; i++)
    if (grau[i] == 0) lista.push_back(i), d[i] = 1;
  while (!lista.empty()) {
    int x = lista[0];
    lista.pop_front();
    for (auto v : aux[x]) {
      grau[v]--;
      d[v] = max(d[v], d[x] + 1);
      if (!grau[v]) lista.push_back(v);
    }
  }
  for (int i = 1; i <= n; i++)
    if (d[i] == n) return true;
  return false;
}
int processed[100050];
bool verif() {
  for (int i = 1; i <= n; i++) {
    if (processed[dp[i]]) return false;
    processed[dp[i]] = 1;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1, a, b; i <= m; i++) {
    cin >> a >> b;
    grafo[a].push_back(b);
    grau[b]++;
    edge.push_back(pair<int, int>(a, b));
  }
  for (int i = 1; i <= n; i++)
    if (!grau[i]) lista.push_back(i), dp[i] = 1;
  for (int i = 0; i < lista.size(); i++) {
    int x = lista[i];
    for (auto v : grafo[x]) {
      grau[v]--;
      if (grau[v] == 0) dp[v] = dp[x] + 1, lista.push_back(v);
    }
  }
  int ini = 1, fim = m, mid, best = -1;
  while (fim >= ini) {
    mid = (ini + fim) / 2;
    if (solve(mid)) {
      best = mid;
      fim = mid - 1;
    } else
      ini = mid + 1;
  }
  cout << best << "\n";
}
