#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000;
vector<int> adj[maxn];
vector<int> order;
int n, m;
vector<int> a(maxn), b(maxn);
vector<int> dp(maxn);
vector<int> visited(maxn, 0);
void dfs(int v) {
  visited[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    if (!visited[adj[v][i]]) dfs(adj[v][i]);
  }
  order.push_back(v);
}
bool solve(int sz) {
  for (int i = 0; i <= n; i++) {
    adj[i].clear();
    dp[i] = 0;
  }
  for (int i = 1; i <= sz; i++) {
    adj[a[i]].push_back(b[i]);
  }
  for (int i = 0; i < order.size(); i++) {
    int v = order[i];
    dp[v] = 1;
    for (int j = 0; j < adj[v].size(); j++) {
      int u = adj[v][j];
      dp[v] = max(dp[u] + 1, dp[v]);
    }
  }
  int max1 = 0;
  for (int i = 0; i <= n; i++) max1 = max(max1, dp[i]);
  if (max1 == n)
    return true;
  else
    return false;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
      cin >> a[i] >> b[i];
      adj[a[i]].push_back(b[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (!visited[i]) dfs(i);
    }
    if (solve(m) == false) {
      cout << -1 << endl;
      exit(0);
    }
    int low = 0;
    int high = m;
    while (low < high) {
      int mid = (low + high) / 2;
      if (solve(mid))
        high = mid;
      else
        low = mid + 1;
    }
    cout << low << endl;
  }
  return 0;
}
