#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 100005;
int h[N], boy[N], cnt[N], du[N];
bool vis[N];
int tot, mid;
struct edge {
  int u;
  int v;
} e[N * 50];
inline void add(int u, int v) {
  tot++;
  e[tot].v = v;
  e[tot].u = h[u];
  h[u] = tot;
}
int main() {
  int n, m;
  int ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    du[y]++;
  }
  int num = 0, cnt = 0;
  queue<int> q;
  for (int i = 1; i <= n; ++i) {
    if (du[i] == 0) {
      num++;
      q.push(i);
    }
  }
  while (!q.empty()) {
    if (num > 1) {
      printf("-1\n");
      return 0;
    }
    int u = q.front();
    q.pop();
    num--;
    for (int i = h[u]; i; i = e[i].u) {
      int v = e[i].v;
      du[v]--;
      if (du[v] == 0) {
        q.push(v);
        num++;
        ans = max(ans, i);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
