#include <bits/stdc++.h>
using namespace std;
int n, m, in1[100005];
int tot = 0, Next[100005 * 2], to[100005 * 2], head[100005 * 2], id[100005 * 2];
queue<int> q;
inline void add(int x, int y, int z) {
  Next[++tot] = head[x];
  id[tot] = z;
  to[tot] = y;
  head[x] = tot;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    int i, x, y, re = 0, bo = 0;
    memset(head, 0, sizeof head);
    memset(in1, 0, sizeof in1);
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &x, &y);
      add(x, y, i);
      in1[y]++;
    }
    for (i = 1; i <= n; i++)
      if (!in1[i]) q.push(i);
    if (q.size() > 1) {
      printf("-1\n");
      continue;
    }
    while (!q.empty()) {
      if (q.size() > 1) {
        bo = 1;
        break;
      }
      int x = q.front();
      q.pop();
      for (i = head[x]; i; i = Next[i]) {
        int V = to[i];
        in1[V]--;
        if (!in1[V]) {
          re = max(re, id[i]);
          q.push(V);
        }
      }
    }
    if (bo)
      printf("-1\n");
    else
      printf("%d\n", re);
  }
}
