#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long t = bin_pow(a, b / 2);
    return t * t % 1000000007;
  } else
    return a * bin_pow(a, b - 1) % 1000000007;
}
long long t = 1, n, m, k = 0, x = 0, y = 0, z = 0, sum = 0, l = 0, r = 0,
          ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;
long long dp[100000];
vector<pair<long long, long long> > a;
vector<long long> graph[100000], order;
bool used[100000];
void dfs(long long v) {
  used[v] = true;
  for (auto u : graph[v]) {
    if (used[u]) continue;
    dfs(u);
  }
  order.push_back(v);
}
bool tr(long long x) {
  for (int i = 0; i < n; i++) graph[i].clear(), used[i] = false, dp[i] = 0;
  order.clear();
  for (int i = 0; i < x; i++) {
    y = a[i].first;
    z = a[i].second;
    graph[y].push_back(z);
  }
  for (int i = 0; i < n; i++) {
    if (used[i]) continue;
    dfs(i);
  }
  reverse(order.begin(), order.end());
  mx = 0;
  for (int i = n - 2; i >= 0; i--) {
    long long j = order[i];
    for (auto u : graph[j]) {
      dp[j] = max(dp[j], dp[u] + 1);
    }
    mx = max(mx, dp[j]);
  }
  return mx == n - 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    a.push_back({x, y});
  }
  for (int b = 1e5; b >= 1; b /= 2) {
    while (ans + b <= m && !tr(ans + b)) ans += b;
  }
  if (ans != m)
    cout << ans + 1;
  else
    cout << -1;
  return 0;
}
