#include <bits/stdc++.h>
using namespace std;
inline void io() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void PV(vector<long long> v) {
  for (long long i = 0; i < (long long)v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PA(long long v[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cout << v[i] << " ";
  cout << "\n";
}
void IA(long long a[], long long n, long long x = 0) {
  for (long long i = x; i < n + x; i++) cin >> a[i];
}
const long long N = 1e5 + 7, Mod = 1e9 + 7, INF = 1e17 + 7;
long long n, m, pl[N], d[N];
vector<vector<pair<long long, long long>>> v(N);
long long tell(long long a) {
  if (pl[a]) return pl[a];
  pl[a] = 1;
  for (auto p : v[a]) {
    long long b = p.first, bl = tell(b);
    if (bl + 1 > pl[a]) {
      pl[a] = bl + 1;
      d[a] = max(d[b], p.second);
    }
  }
  return pl[a];
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    v[a].push_back({b, i + 1});
  }
  for (long long i = 1; i < n + 1; i++) {
    if (tell(i) == n) {
      cout << d[i];
      return;
    }
  }
  cout << -1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t1 = 1;
  cout << fixed << setprecision(11);
  while (t1--) {
    solve();
  }
}
