#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
const int N = 1e6 + 100;
int n, m;
int u[N], v[N];
set<int> g[N];
bool used[N];
int ts[N], tsLen = 0;
void topSort(int v) {
  if (used[v]) {
    return;
  }
  used[v] = true;
  for (int to : g[v]) {
    topSort(to);
  }
  ts[tsLen++] = v;
}
inline bool check(int m) {
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < m; i++) {
    g[u[i]].insert(v[i]);
  }
  fill_n(used, n, false);
  tsLen = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      topSort(i);
    }
  }
  reverse(ts, ts + tsLen);
  for (int i = 0; i < tsLen - 1; i++) {
    if (g[ts[i]].count(ts[i + 1]) == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    u[i]--, v[i]--;
  }
  int l = 0, r = m;
  while (r - l > 1) {
    int x = (l + r) / 2;
    if (check(x)) {
      r = x;
    } else {
      l = x;
    }
  }
  if (!check(r)) {
    puts("-1");
  } else {
    printf("%d\n", r);
  }
  return 0;
}
