#include <bits/stdc++.h>
using namespace std;
vector<int> g[100500];
int income[100500];
int a[100500];
int b[100500];
int c[100500];
int n, m;
void dbg() {
  for (int i = 0; i < n; ++i) printf("%i ", c[i]);
  printf("\n");
}
bool order(int q) {
  int x, y, k;
  for (int i = 1; i <= n; ++i) {
    g[i].clear();
    income[i] = 0;
  }
  for (int i = 0; i < q; ++i) {
    g[a[i]].push_back(b[i]);
    income[b[i]]++;
  }
  x = y = 0;
  for (int i = 1; i <= n; ++i) {
    if (income[i] == 0) {
      x = i;
      y++;
    }
  }
  if (y != 1) return false;
  k = 0;
  while (true) {
    c[k++] = x;
    for (int i = 0; i < g[x].size(); ++i) {
      int v = g[x][i];
      income[v]--;
    }
    y = 0;
    for (int i = 0; i < g[x].size(); ++i) {
      int v = g[x][i];
      if (income[v] == 0) y = v;
    }
    if (y == 0) break;
    x = y;
  }
  if (k != n) return false;
  return true;
}
int main() {
  scanf("%i%i", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%i%i", &a[i], &b[i]);
  }
  if (!order(m)) {
    printf("-1\n");
    return 0;
  }
  int A = 1;
  int B = m;
  while (B - A > 1) {
    int C = (A + B) / 2;
    if (order(C))
      B = C;
    else
      A = C;
  }
  if (order(A)) {
    printf("%i\n", A);
  } else {
    printf("%i\n", A + 1);
  }
  return 0;
}
