#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;
int n, m;
vector<pair<int, int> > g[maxn];
int u[maxn], dp[maxn], ans[maxn];
int go(int v) {
  if (dp[v]) return dp[v];
  dp[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first;
    int ind = g[v][i].second;
    if (go(to) + 1 > dp[v]) {
      dp[v] = dp[to] + 1;
      ans[v] = max(ans[to], ind);
    }
  }
  return dp[v];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u = 0, v = 0;
    scanf("%d%d", &u, &v);
    g[u].push_back(make_pair(v, i));
  }
  for (int i = 1; i <= n; i++) {
    if (go(i) == n) {
      printf("%d\n", ans[i]);
      return 0;
    }
  }
  printf("-1");
  return 0;
}
