#include <bits/stdc++.h>
using namespace std;
int arr[2][100009], n, m;
bool check(int x) {
  int vis[100009] = {0};
  vector<int> graph[100009];
  for (int f = 0; f <= x; f++) {
    graph[arr[1][f]].push_back(arr[0][f]);
    vis[arr[0][f]]++;
  }
  queue<int> q;
  for (int f = 1; f <= n; f++) {
    if (vis[f] == 0) q.push(f);
  }
  int c = 0;
  while (q.size()) {
    if (q.size() > 1) return 0;
    for (int f = 0; f < graph[q.front()].size(); f++) {
      vis[graph[q.front()][f]]--;
      if (vis[graph[q.front()][f]] == 0) q.push(graph[q.front()][f]);
    }
    q.pop();
    c++;
  }
  if (c < n) return 0;
  return 1;
}
int ans = -1;
void bs(int a, int b) {
  if (b < a) return;
  int mid = (a + b) / 2;
  if (check(mid)) {
    ans = mid + 1;
    bs(a, mid - 1);
  } else
    bs(mid + 1, b);
}
int main() {
  cin >> n >> m;
  for (int f = 0; f < m; f++) cin >> arr[0][f] >> arr[1][f];
  bs(0, m - 1);
  cout << ans << endl;
}
