#include <bits/stdc++.h>
using namespace std;
long long n, m;
pair<long long, long long> arr[100005];
vector<long long> adj[100005];
long long deg[100005];
long long visit[100005];
long long dfs(long long curr) {
  visit[curr] = 0;
  for (auto x : adj[curr]) {
    if (visit[x] == 0) dfs(x);
    visit[curr] = max(visit[curr], visit[x]);
  }
  visit[curr]++;
  return visit[curr];
}
long long check(long long cnt) {
  memset(deg, 0, sizeof(deg));
  memset(visit, 0, sizeof(visit));
  for (long long i = 0; i < m + 1; i++) adj[i].clear();
  for (long long i = 0; i < cnt + 1; i++) {
    adj[arr[i].first].push_back(arr[i].second);
    deg[arr[i].second] = 1;
  }
  long long source = -1;
  for (long long i = 1; i <= n; i++) {
    if (deg[i] == 0) source = i;
  }
  if (source == -1) return 0;
  dfs(source);
  for (long long i = 1; i <= n; i++) {
    if (visit[i] == n) return 1;
  }
  return 0;
}
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    arr[i] = {x, y};
  }
  long long start = 0, end = m - 1, ans = -1;
  while (start <= end) {
    long long mid = (start + end) / 2;
    if (check(mid)) {
      ans = mid + 1;
      end = mid - 1;
    } else
      start = mid + 1;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
