#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int>> G[123123];
int ans;
int ins[123123];
int main() {
  scanf("%d%d", &n, &m);
  int x, y;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    G[y].push_back(make_pair(x, i));
    ++ins[x];
  }
  vector<int> free;
  for (int i = 1; i <= n; ++i)
    if (!ins[i]) free.push_back(i);
  if (free.size() != 1) {
    printf("-1\n");
    return 0;
  }
  while (free.size()) {
    int node = free[0];
    free.clear();
    for (int i = 0; i < G[node].size(); ++i) {
      int sas = G[node][i].first;
      --ins[sas];
      if (!ins[sas]) {
        free.push_back(sas);
        ans = max(ans, G[node][i].second);
      }
    }
    if (free.size() > 1) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", ans);
}
