#include <bits/stdc++.h>
using namespace std;
long long int N = 100007;
vector<vector<pair<long long int, long long int> > > G;
vector<long long int> res(N), dp(N, -1);
long long int longestPath(long long int r) {
  if (dp[r] != -1) {
    return dp[r];
  } else {
    dp[r] = 1;
    for (auto i : G[r]) {
      long long int c = i.first;
      if (longestPath(c) + 1 > dp[r]) {
        dp[r] = dp[c] + 1;
        res[r] = max(i.second, res[c]);
      }
    }
    return dp[r];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  G.resize(n + 1);
  for (long long int i = 0; i < k; i++) {
    long long int x, y;
    cin >> x >> y;
    G[x].push_back(make_pair(y, i + 1));
  }
  for (long long int i = 0; i <= n; i++) {
    if (longestPath(i) == n) {
      cout << res[i] << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}
