#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > a;
vector<vector<int> > g;
vector<int> u, d;
int dfs(int x) {
  if (d[x] != 0) return d[x];
  int ans = 1;
  for (int i = 0; i < (int)g[x].size(); ++i) {
    ans = max(ans, dfs(g[x][i]) + 1);
  }
  return d[x] = ans;
}
bool solve(int f) {
  g.assign(g.size(), vector<int>());
  u.assign(u.size(), 0);
  d.assign(d.size(), 0);
  for (int i = 0; i < f; ++i) {
    int x = a[i].first, y = a[i].second;
    g[y].push_back(x);
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (!u[i]) {
      ans = max(ans, dfs(i));
    }
  }
  return ans == n;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  g.resize(n + 1);
  u.resize(n + 1);
  d.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  int l = -1, r = m + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (solve(mid))
      r = mid;
    else
      l = mid;
  }
  int ans = l + 1;
  if (ans == m + 1) ans = -1;
  cout << ans;
  return 0;
}
