#include <bits/stdc++.h>
using namespace std;
int n, m, s;
vector<int> a[100010], b[100010];
bool c[100010];
int nop[100010], noc[100010];
pair<int, int> r[100010];
int count_child(int u) {
  if (noc[u] != -1) return noc[u];
  int cur = 1;
  for (int v : a[u]) {
    cur = max(cur, count_child(v) + 1);
  }
  return noc[u] = cur;
}
int count_parent(int u) {
  if (nop[u] != -1) return nop[u];
  int cur = 1;
  for (int v : b[u]) {
    cur = max(cur, count_parent(v) + 1);
  }
  return nop[u] = cur;
}
bool check(int x) {
  for (int i = 1; i <= n; i++) a[i].clear(), b[i].clear();
  memset(nop, -1, sizeof(nop));
  memset(noc, -1, sizeof(noc));
  for (int i = 1; i <= x; i++) {
    int u = r[i].first;
    int v = r[i].second;
    a[u].push_back(v);
    b[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (count_parent(i) + count_child(i) - 1 != n) return false;
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    r[i] = pair<int, int>(u, v);
  }
  int l = 0, r = m + 1, mid;
  while (r - l > 1) {
    mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  if (r == m + 1)
    printf("-1\n");
  else
    printf("%d\n", r);
}
