#include <bits/stdc++.h>
using namespace std;
vector<int> G[100005];
int a[100005], b[100005], dp[100005], n, m;
int dfs(int x) {
  if (dp[x] != -1) return dp[x];
  int ans = 1;
  for (int i : G[x]) ans = max(ans, dfs(i) + 1);
  return dp[x] = ans;
}
bool check(int k) {
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i) G[i].clear();
  for (int i = 0; i < k; ++i) G[a[i]].emplace_back(b[i]);
  for (int i = 1; i <= n; ++i)
    if (dfs(i) == n) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) cin >> a[i] >> b[i];
  int l = 1, r = m + 1, mid;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << (r == m + 1 ? -1 : l) << '\n';
  return 0;
}
