#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int Maxn = 1e6;
const long long MAX = -1e18;
struct Dn {
  int x, l;
};
int n, m, a, b, ans = 0;
int ind[Maxn];
vector<Dn> JQ[Maxn];
bool check() {
  queue<int> Q;
  for (int i = 1; i <= n; i++)
    if (ind[i] == 0) Q.push(i);
  while (!Q.empty()) {
    if (Q.size() > 1) return false;
    int S = Q.front();
    Q.pop();
    for (int i = 0; i < JQ[S].size(); i++) {
      ind[JQ[S][i].x]--;
      if (ind[JQ[S][i].x] == 0) {
        Q.push(JQ[S][i].x);
        ans = max(ans, JQ[S][i].l);
      }
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    JQ[a].push_back((Dn){b, i});
    ind[b]++;
  }
  if (check())
    printf("%d", ans);
  else
    printf("-1\n");
}
