#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int parent[MAXN];
int n, m;
vector<int> adj[MAXN];
int s[MAXN], e[MAXN];
int degree[MAXN];
bool check(int x) {
  for (int i = 1; i <= n; i++) adj[i].clear(), degree[i] = 0;
  for (int i = 1; i <= x; i++) {
    adj[s[i]].push_back(e[i]);
    degree[e[i]]++;
  }
  vector<int> best;
  vector<int> bestcopy;
  for (int i = 1; i <= n; i++)
    if (degree[i] == 0) best.push_back(i);
  for (int place = 1; place <= n; place++) {
    if (best.size() != 1) return false;
    bestcopy.clear();
    for (int i = 0; i < best.size(); i++) {
      for (int j = 0; j < adj[best[i]].size(); j++) {
        degree[adj[best[i]][j]]--;
        if (degree[adj[best[i]][j]] == 0) bestcopy.push_back(adj[best[i]][j]);
      }
    }
    best = bestcopy;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  int lo = 1;
  int hi = m;
  for (int i = 1; i <= m; i++) scanf("%d%d", &s[i], &e[i]);
  int ans = -1;
  while (lo <= hi) {
    if (check((lo + hi) / 2)) {
      ans = (lo + hi) / 2;
      hi = (lo + hi) / 2 - 1;
    } else
      lo = (lo + hi) / 2 + 1;
  }
  printf("%d\n", ans);
  return 0;
}
