#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MOD = 1000000007;
int n, m;
vector<pair<int, int>> G[MAXN];
int res[MAXN];
int dp[MAXN];
int check(int v) {
  if (dp[v]) return dp[v];
  dp[v] = 1;
  for (int i = 0; i < G[v].size(); i++) {
    int p = G[v][i].first;
    if (check(p) + 1 > dp[v]) {
      dp[v] = dp[p] + 1;
      res[v] = max(res[p], G[v][i].second);
    }
  }
  return dp[v];
}
void init() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(make_pair(b, i + 1));
  }
}
void mainp() {
  for (int i = 0; i < n; i++) {
    if (check(i) == n) {
      cout << res[i] << '\n';
      return;
    }
  }
  cout << -1 << '\n';
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  init();
  mainp();
  return 0;
}
