#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 100000;
int n, m;
vector<int> adj[maxn];
int a[maxn];
bool cmp(pair<int, int> a, pair<int, int> b) {
  return (a.first > b.first) || (a.first == b.first && a.second < b.second);
}
pair<int, int> dp[maxn];
void init() {
  for (int i = 0; i < maxn; i++) dp[i] = pair<int, int>(-1, -1);
}
pair<int, int> run_dp(int v) {
  if (dp[v].first != -1) return dp[v];
  dp[v] = pair<int, int>(1, 0);
  for (int e : adj[v]) {
    pair<int, int> ans = run_dp(a[e]);
    ans.first++;
    (ans.second) = max((ans.second), (e));
    if (cmp(ans, dp[v])) dp[v] = ans;
  }
  return dp[v];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d", &n);
  scanf("%d", &m);
  bool spoild[n];
  memset(spoild, false, sizeof(spoild));
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
    a[i]--;
    int b;
    scanf("%d", &b);
    adj[--b].push_back(i);
    spoild[a[i]] = true;
  }
  int specialsu = 0;
  for (int i = 0; i < n; i++)
    if (!spoild[i]) specialsu = i;
  init();
  pair<int, int> ans = run_dp(specialsu);
  if (ans.first != n)
    cout << -1 << endl;
  else
    cout << ans.second + 1 << endl;
  return 0;
}
