#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
long long INF = 1e18;
int n, m;
int u[100005], v[100005];
int d[100005];
vector<int> g[100005], g2[100005];
int in[100005];
int check(int amt) {
  for (int i = 0; i < n; i++) g[i].clear(), g2[i].clear();
  for (int i = 0; i < amt; i++)
    g[u[i]].push_back(v[i]), g2[v[i]].push_back(u[i]);
  for (int i = 0; i < n; i++) in[i] = g2[i].size();
  queue<int> q;
  vector<int> ts;
  for (int i = 0; i < n; i++)
    if (!in[i]) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    ts.push_back(u);
    for (int v : g[u]) {
      in[v]--;
      if (in[v] == 0) q.push(v);
    }
  }
  for (int i = 0; i < n; i++) d[i] = 0;
  for (int i = 0; i < ts.size(); i++) {
    int u = ts[i];
    for (int v : g[u]) d[v] = max(d[v], d[u] + 1);
  }
  return d[ts[ts.size() - 1]] >= n - 1;
}
int solve() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> u[i] >> v[i], u[i]--, v[i]--;
  if (!check(m)) {
    cout << -1 << endl;
    return 0;
  }
  int lo = 0, hi = m;
  while (lo < hi) {
    int mi = lo + hi >> 1;
    if (check(mi))
      hi = mi;
    else
      lo = mi + 1;
  }
  cout << lo << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  solve();
  return 0;
}
