#include <bits/stdc++.h>
using namespace std;
vector<long long> g[100005];
vector<long long> visited;
vector<pair<long long, long long> > edges;
vector<long long> indegree;
long long n;
bool check(long long m) {
  for (long long i = 0; i < m; i++) {
    pair<long long, long long> p = edges[i];
    long long u = p.first, v = p.second;
    g[u].push_back(v);
    indegree[v]++;
  }
  vector<long long> q;
  for (long long i = 0; i < n; i++) {
    if (indegree[i] == 0) q.push_back(i);
  }
  long long i = 0;
  while (i < (q.size())) {
    for (auto v : g[q[i]]) {
      indegree[v]--;
      if (indegree[v] == 0) q.push_back(v);
    }
    i++;
  }
  for (long long i = 0; i < (q.size()) - 1; i++) {
    long long u = q[i], v = q[i + 1];
    bool flag = 0;
    for (auto x : g[u]) {
      if (x == v) flag = 1;
    }
    if (!flag) return 0;
  }
  return 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long m, i = 0, u, v;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> u >> v;
    u--, v--;
    edges.push_back(make_pair(u, v));
  }
  long long lo = 0, hi = m;
  long long ans = INT_MAX;
  indegree.resize(n);
  visited.resize(n);
  while (lo <= hi) {
    long long mid = (lo + hi) / 2;
    for (long long i = 0; i < n; i++) {
      indegree[i] = 0;
      visited[i] = 0;
      g[i].clear();
    }
    if (check(mid)) {
      ans = min(ans, mid);
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  if (ans == INT_MAX) {
    cout << -1 << "\n";
  } else
    cout << ans << "\n";
  return 0;
}
