#include <bits/stdc++.h>
using namespace std;
map<long long int, list<long long int>> l;
long long int dp[1000020];
map<long long int, bool> visited;
map<pair<long long int, long long int>, long long int> mat;
void addedge(long long int a, long long int b) { l[a].push_back(b); }
void dfs(long long int node) {
  visited[node] = true;
  for (auto it : l[node]) {
    if (!visited[it]) {
      dfs(it);
    }
    dp[node] = max(dp[node], 1 + dp[it]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    long long int a, b;
    cin >> a >> b;
    mat[{a, b}] = i + 1;
    addedge(a, b);
  }
  memset(dp, 0, sizeof(dp));
  for (long long int i = 1; i <= n; i++) {
    if (!visited[i]) {
      dfs(i);
    }
  }
  long long int maxi = -1;
  long long int pos;
  for (long long int i = 1; i <= n; i++) {
    if (dp[i] > maxi) {
      maxi = dp[i];
      pos = i;
    }
  }
  if (maxi != n - 1) {
    cout << "-1" << endl;
  } else {
    long long int arr[n + 1];
    long long int cnt = 0;
    while (dp[pos] != 0) {
      long long int maxi = -1;
      arr[cnt] = pos;
      cnt++;
      for (auto it : l[pos]) {
        if (dp[it] > maxi) {
          maxi = dp[it];
          pos = it;
        }
      }
    }
    arr[cnt] = pos;
    cnt++;
    vector<pair<long long int, long long int>> vec;
    long long int maxans = -1;
    for (long long int i = 0; i < cnt - 1; i++) {
      maxans = max(maxans, mat[{arr[i], arr[i + 1]}]);
    }
    cout << maxans << endl;
  }
}
