#include <bits/stdc++.h>
using namespace std;
struct ac {
  int v;
  int edgeIdx;
  ac *next;
} * table[100100];
int deg[100100];
int a[100100];
bool use[100100];
int n, m, c;
void insert(int x, int y, int idx) {
  ac *p = new ac();
  p->v = y;
  p->edgeIdx = idx;
  p->next = table[x];
  table[x] = p;
}
void input() {
  int i;
  int x, y;
  for (i = 0; i <= n; i++) {
    table[i] = NULL;
    deg[i] = 0;
    use[i] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    deg[y]++;
    insert(x, y, i + 1);
  }
}
void dfs(int node) {
  c++;
  use[node] = true;
  ac *p = table[node];
  while (p != NULL) {
    deg[p->v]--;
    p = p->next;
  }
  p = table[node];
  while (p != NULL) {
    if (deg[p->v] == 0 && !use[p->v]) {
      a[p->v] = p->edgeIdx;
      dfs(p->v);
      break;
    }
    p = p->next;
  }
}
void solve() {
  int i, root;
  c = 0;
  for (i = 1; i <= n; i++) {
    if (deg[i] == 0) {
      a[i] = 0;
      root = i;
      dfs(i);
      break;
    }
  }
  if (c != n) {
    printf("-1\n");
  } else {
    int ans = 0;
    for (i = 1; i <= n; i++) {
      if (ans < a[i]) {
        ans = a[i];
      }
    }
    printf("%d\n", ans);
  }
}
int main() {
  while (scanf("%d %d", &n, &m) != EOF) {
    input();
    solve();
  }
  return 0;
}
