#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a[100005];
int n, m;
int dp[100005];
int vis[300005];
bool dfs(int k) {
  if (vis[k] == 2) return false;
  if (vis[k] == 1) return true;
  vis[k] = 1;
  for (int i = 0; i < a[k].size(); i++)
    if (dfs(a[k][i].first)) return true;
  vis[k] = 2;
  return false;
}
int rec(int u, int mid) {
  if (dp[u] != -1) return dp[u];
  int mx = 1;
  for (int i = 0; i < a[u].size(); i++) {
    int ins = a[u][i].first;
    int ed = a[u][i].second;
    if (ed <= mid) {
      mx = max(mx, 1 + rec(ins, mid));
    }
  }
  return dp[u] = mx;
}
int check(int ed) {
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    if (rec(i, ed) == n) return 1;
  }
  return 0;
}
int main() {
  int i, u, v;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    a[v].push_back(make_pair(u, i + 1));
  }
  for (i = 1; i <= n; i++) {
    if (!vis[i] && dfs(i)) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int lo = 1, hi = m;
  while (hi - lo >= 6) {
    int mid = (hi + lo) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid;
  }
  int ans = -1;
  for (i = lo; i <= hi; i++) {
    if (check(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
