#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> edges;
vector<vector<int>> g1, g2;
vector<int> dp;
vector<int> used;
void dfs(int v) {
  used[v] = 1;
  if (g1[v].size() == 0) {
    dp[v] = 1;
    return;
  }
  for (auto u : g1[v]) {
    if (!used[u]) dfs(u);
    dp[v] = max(dp[v], dp[u]);
  }
  dp[v]++;
}
int check(int k) {
  dp.clear();
  dp.resize(n);
  used.clear();
  used.resize(n);
  g1.clear();
  g1.resize(n);
  g2.clear();
  g2.resize(n);
  int root = -1;
  for (int i = 0; i < k; i++) {
    int x, y;
    tie(x, y) = edges[i];
    g1[x].push_back(y);
    g2[y].push_back(x);
  }
  int val1 = 0, val2 = 0;
  for (int i = 0; i < n; i++) {
    if (g1[i].size() == 0) {
      val1++;
    }
    if (g2[i].size() == 0) {
      root = i;
      val2++;
    }
  }
  if (val1 + val2 > 2) return 0;
  dfs(root);
  return (dp[root] == n);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    edges.push_back({x, y});
  }
  int l = 0, r = m;
  while (l < r - 1) {
    int m1 = (l + r) / 2;
    if (!check(m1)) {
      l = m1;
    } else {
      r = m1;
    }
  }
  if (!check(r)) {
    cout << -1;
    return 0;
  }
  cout << r;
}
