#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int n, m, val[N];
vector<int> g[N];
pair<int, int> a[N];
int dfs(int u) {
  if (val[u] != -1) return val[u];
  val[u] = 1;
  int mx = 0;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    mx = max(mx, dfs(v));
  }
  val[u] = val[u] + mx;
  return val[u];
}
int cal(int t) {
  for (int i = 1; i <= n; ++i) g[i].clear();
  for (int i = 0; i < t; ++i) g[a[i].first].push_back(a[i].second);
  memset(val, -1, sizeof(val));
  int mx = 0;
  for (int i = 1; i <= n; ++i) mx = max(mx, dfs(i));
  return mx;
}
int solve() {
  int lo = 1, hi = m, mid = (lo + hi) / 2;
  while (lo != mid && hi != mid) {
    if (cal(mid) < n) {
      lo = mid;
    } else
      hi = mid;
    mid = (lo + hi) / 2;
  }
  for (; lo <= hi; ++lo)
    if (cal(lo) == n) return lo;
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    a[i] = make_pair(u, v);
  }
  cout << solve();
  return 0;
}
