#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
vector<pair<int, int> > graph[MAXN];
int dp[MAXN], ans[MAXN];
int solve(int start) {
  if (dp[start] != 0) return dp[start];
  dp[start] = 1;
  for (int i = 0; i < graph[start].size(); i++) {
    if (solve(graph[start][i].first) + 1 > dp[start]) {
      dp[start] = dp[graph[start][i].first] + 1;
      ans[start] = max(ans[graph[start][i].first], graph[start][i].second);
    }
  }
  return dp[start];
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back({y, i});
  }
  for (int i = 1; i <= n; i++) {
    if (solve(i) == n) {
      cout << ans[i] << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
