#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long powM(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = powM(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
vector<int> v[100002];
vector<bool> vis(100002, 0);
int dp[100002] = {};
void dfs(int s) {
  vis[s] = 1;
  for (auto u : v[s]) {
    if (vis[u] == 0) dfs(u);
    dp[s] = max(dp[s], dp[u] + 1);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int a[m + 1], b[m + 1];
  for (long long i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
  }
  int l = 1, r = m, ans = -1;
  for (long long i = 1; i <= n; i++) dp[i] = 1;
  while (l <= r) {
    int md = l + (r - l) / 2;
    for (long long i = 1; i <= md; i++) v[a[i]].push_back(b[i]);
    set<int> st;
    for (long long i = 1; i <= n; i++) st.insert(i);
    for (long long i = 1; i <= md; i++) {
      st.erase(b[i]);
    }
    if (st.size() > 1) {
      l = md + 1;
      continue;
    }
    int rt = *st.begin();
    dfs(rt);
    if (dp[rt] == n) {
      ans = md;
      r = md - 1;
    } else {
      l = md + 1;
    }
    for (long long i = 1; i <= n; i++) {
      v[i].clear();
      vis[i] = 0;
      dp[i] = 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
