#include <bits/stdc++.h>
using namespace std;
const int N = 202020;
struct node {
  int u, v, next;
} e[N];
int head[N], cnt;
void add(int u, int v) {
  e[cnt] = node{u, v, head[u]};
  head[u] = cnt++;
}
int n, m;
int q[N];
int in[N];
int main() {
  while (cin >> n >> m) {
    memset(head, -1, sizeof(head));
    cnt = 0;
    memset(in, 0, sizeof(in));
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
      in[v]++;
    }
    int ans = 0;
    int tail = 0, flag = 1;
    for (int i = 1; i <= n; i++)
      if (in[i] == 0) q[tail++] = i;
    if (tail > 1) flag = 0;
    for (int i = 0; i < tail; i++) {
      int t = q[i];
      int res = 0;
      for (int j = head[t]; ~j; j = e[j].next) {
        if (--in[e[j].v] == 0) {
          q[tail++] = e[j].v;
          res++;
          ans = max(ans, j);
        }
      }
      if (res > 1) flag = 0;
    }
    if (flag == 0 || tail < n)
      cout << -1 << endl;
    else
      cout << ans + 1 << endl;
  }
}
