#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > adj[N];
vector<int> topoo;
int used[N];
void topo(int x) {
  for (int i = 0; i < adj[x].size(); i++) {
    if (!used[adj[x][i].first]) {
      used[adj[x][i].first] = 1;
      topo(adj[x][i].first);
      used[adj[x][i].first] = 2;
    } else {
      if (used[adj[x][i].first] == 1) {
        cout << -1;
        exit(0);
      }
    }
  }
  topoo.push_back(x);
}
int main() {
  int n, m, i, j, k, ans = 0;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    adj[j].push_back({k, i});
  }
  for (i = 1; i <= n; i++) {
    if (!used[i]) {
      used[i] = 1;
      topo(i);
      used[i] = 2;
    }
  }
  for (i = topoo.size() - 1; i > 0; i--) {
    for (j = 0; j < adj[topoo[i]].size(); j++) {
      if (adj[topoo[i]][j].first == topoo[i - 1]) {
        ans = max(ans, adj[topoo[i]][j].second);
        break;
      }
      if (j == adj[topoo[i]].size() - 1) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << ans;
}
