#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const double eps = 1e-10;
const long long N = 1e5 + 7;
const long long MOD = 1e9 + 7;
long long pw(long long b, long long p) {
  b %= MOD;
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * b % MOD;
    b = b * b % MOD;
    p >>= 1;
  }
  return res;
}
long long n, m;
vector<long long> dp(N), ans(N);
vector<vector<pair<long long, long long> > > g(N);
long long dfs(long long u) {
  if (dp[u]) return dp[u];
  dp[u] = 1;
  for (auto i : g[u]) {
    if (dfs(i.first) + 1 > dp[u]) {
      dp[u] = dp[i.first] + 1;
      ans[u] = max(ans[i.first], i.second);
    }
  }
  return dp[u];
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  long long u, v;
  for (long long i = 1; i < m + 1; i++) {
    cin >> u >> v;
    g[u].emplace_back(v, i);
  }
  for (long long i = 1; i < n + 1; i++) {
    if (dfs(i) == n) {
      cout << ans[i];
      return 0;
    }
  }
  cout << -1;
  return 0;
}
