#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
vector<pair<int, int>> v[N];
int in_deg[N], maxi = 0, cnt = 0, n, first = 0;
queue<pair<int, int>> q;
void toplogical() {
  while (!q.empty()) {
    int x = q.front().first, lvl = q.front().second;
    if (lvl == n - 1) {
      first = 1;
      break;
    }
    q.pop();
    for (auto i : v[x]) {
      if (--in_deg[i.first] == 0) {
        q.push({i.first, lvl + 1});
        maxi = max(maxi, i.second);
      }
    }
  }
}
int main() {
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, e;
    cin >> u >> e;
    v[u].push_back({e, i + 1});
    in_deg[e]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!in_deg[i]) q.push({i, 0});
  }
  toplogical();
  if (first)
    cout << maxi;
  else
    cout << -1;
}
