#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
static const int N = 1e5 + 10;
int n, m, dp[N], vis[N];
vector<pair<int, int> > G[N];
void dfs(int v, int lim) {
  vis[v] = true;
  for (auto u : G[v]) {
    if (u.second <= lim) {
      if (!vis[u.first]) dfs(u.first, lim);
      dp[v] = max(dp[v], dp[u.first] + 1);
    }
  }
}
bool check(int cnt) {
  fill(vis, vis + n + 1, false);
  fill(dp, dp + n + 1, 1);
  int longest = 0;
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) dfs(i, cnt);
    longest = max(longest, dp[i]);
  }
  return longest == n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].push_back({v, i + 1});
  }
  if (!check(m)) {
    cout << -1 << "\n";
    return 0;
  }
  int low = n - 1, high = m;
  while (low < high) {
    int mid = (low + high) / 2;
    if (check(mid))
      high = mid;
    else
      low = mid + 1;
  }
  if (check(low))
    cout << low << "\n";
  else
    cout << low - 1 << "\n";
}
