#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100000 + 5];
vector<int> ret;
int u[100000 + 5], v[100000 + 5], in[100000 + 5];
int n, m;
bool ok(int mid) {
  for (int i = 1; i <= n; i++) {
    in[i] = 0;
    while (!adj[i].empty()) adj[i].pop_back();
  }
  while (!ret.empty()) ret.pop_back();
  for (int i = 1; i <= mid; i++) {
    adj[u[i]].push_back(v[i]);
    in[v[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) ret.push_back(i);
  for (int i = 1; i <= n; i++) {
    if (ret.size() >= 2) return false;
    int u = ret.back();
    ret.pop_back();
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j];
      in[v]--;
      if (in[v] == 0) ret.push_back(v);
    }
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d", &u[i], &v[i]);
  if (!ok(m)) {
    printf("-1");
    return 0;
  }
  int lo = 1, hi = m;
  while (lo < hi) {
    int mid = (lo + hi) / 2;
    if (ok(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  printf("%d", lo);
}
