#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, l[maxn], r[maxn], in[maxn];
vector<int> vec[maxn];
bool tuopu() {
  queue<int> q;
  int temp = 0;
  for (int i = 1; i <= n; i++)
    if (in[i] == 0) temp++, q.push(i);
  if (temp != 1) return false;
  while (!q.empty()) {
    int u = q.front(), lin = 0;
    q.pop();
    for (int i = 0; i < vec[u].size(); i++) {
      int v = vec[u][i];
      if (--in[v] == 0) q.push(v), temp++, lin++;
    }
    if (lin > 1) return false;
  }
  if (temp != n) return false;
  return true;
}
void init(int mid) {
  for (int i = 1; i <= n; i++) vec[i].clear(), in[i] = 0;
  for (int i = 1; i <= mid; i++) {
    vec[r[i]].push_back(l[i]);
    in[l[i]]++;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) scanf("%d%d", &l[i], &r[i]);
  int L = 1, R = m, mid, ans = -1;
  while (R >= L) {
    mid = L + R >> 1;
    init(mid);
    if (tuopu())
      R = mid - 1, ans = mid;
    else
      L = mid + 1;
  }
  cout << ans;
}
