#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int N, M, dp[maxn], res[maxn];
vector<pair<int, int> > adj[maxn];
int check(int v) {
  if (dp[v]) return dp[v];
  dp[v] = 1;
  for (auto p : adj[v]) {
    int n = p.first;
    if (check(n) + 1 > dp[v]) {
      dp[v] = dp[n] + 1;
      res[v] = max(res[n], p.second);
    }
  }
  return dp[v];
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    adj[u].push_back({v, i + 1});
  }
  for (int i = 0; i < N; i++) {
    if (check(i) == N) {
      printf("%d\n", res[i]);
      return 0;
    }
  }
  printf("-1\n");
}
