#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, u, v, cnt[N], have[N], point[N];
vector<pair<int, int> > win[N], lose[N];
void shoot_out(int dex, int u) {
  have[cnt[u]]--;
  for (int i = 0; i < lose[u].size() && lose[u][i].second <= dex; i++) {
    int v = lose[u][i].first;
    have[cnt[v]]--;
    cnt[v]--;
    have[cnt[v]]++;
    point[cnt[v]] = v;
  }
}
bool check(int dex) {
  memset(cnt, 0, sizeof cnt);
  memset(have, 0, sizeof have);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < win[i].size() && win[i][j].second <= dex; j++) cnt[i]++;
    point[cnt[i]] = i;
    have[cnt[i]]++;
  }
  for (int i = 0; i < n; i++)
    if (have[0] != 1)
      return false;
    else
      shoot_out(dex, point[0]);
  return true;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    win[--u].push_back(pair<int, int>(--v, i));
    lose[v].push_back(pair<int, int>(u, i));
  }
  int l = -1, r = m;
  while (r - l > 1) {
    int c = (l + r) / 2;
    if (check(c))
      r = c;
    else
      l = c;
  }
  cout << (r == m ? -1 : r + 1);
  return 0;
}
