#include <bits/stdc++.h>
using namespace std;
int u[100010], v[100010];
vector<int> g[100010];
int dp[100010];
int func(int x) {
  if (dp[x] != -1) return dp[x];
  int ans = 0;
  for (int _n((int)g[x].size()), i(0); i < _n; i++)
    ans = max(ans, func(g[x][i]) + 1);
  return dp[x] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int _n(m), i(0); i < _n; i++) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    g[u[i]].push_back(v[i]);
  }
  for (int _n(n), i(0); i < _n; i++) dp[i] = -1;
  for (int _n(n), i(0); i < _n; i++) dp[i] = func(i);
  bool found = false;
  for (int _n(n), i(0); i < _n; i++)
    if (dp[i] == n - 1) found = true;
  if (!found) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int _n(m), i(0); i < _n; i++)
    if (dp[u[i]] - dp[v[i]] == 1) ans = max(ans, i + 1);
  cout << ans << endl;
  return 0;
}
