#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
vector<pair<int, int> > edges;
vector<int> par[N], adj[N];
int dist[N], cnt[N], dp[N];
int n, m;
int solve(int node) {
  if (dp[node] != -1) return dp[node];
  dp[node] = 1;
  for (auto tail : adj[node]) dp[node] = max(dp[node], 1 + solve(tail));
  return dp[node];
}
bool possible(int k) {
  for (int i = 0; i <= n; i++) adj[i].clear(), par[i].clear();
  int root = n;
  for (int i = 0; i < k; i++) {
    par[edges[i].second].push_back(edges[i].first);
    adj[edges[i].first].push_back(edges[i].second);
    root = edges[i].first;
  }
  while (!par[root].empty()) root = par[root][0];
  memset(dp, -1, sizeof(dp));
  int ans = solve(root);
  if (ans < n) return false;
  return true;
}
int main() {
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    edges.push_back({u, v});
  }
  int low = 0, high = m + 1;
  while ((high - low) > 1) {
    int mid = (high + low) / 2;
    if (possible(mid))
      high = mid;
    else
      low = mid;
  }
  high = min(high, m);
  if (possible(high))
    cout << high;
  else
    cout << -1;
  return 0;
}
