#include <bits/stdc++.h>
using namespace std;
const int N = 100500;
int V[N], U[N];
int cnt[N];
int n, m;
set<pair<int, int> > s;
vector<pair<int, int> > g[N];
bool solved(int mx) {
  for (int i = 0; i < n; i++) cnt[i] = 0;
  for (int i = 0; i < mx; i++) cnt[U[i]]++;
  s.clear();
  for (int i = 0; i < n; i++) s.insert(make_pair(cnt[i], i));
  for (int i = 1; i < n; i++) {
    int v = s.begin()->second;
    int dv = s.begin()->first;
    s.erase(s.begin());
    if (dv != 0 || s.begin()->first == 0) return false;
    for (int j = 0; j < g[v].size(); j++) {
      if (g[v][j].second < mx) {
        int u = g[v][j].first;
        s.erase(make_pair(cnt[u], u));
        cnt[u]--;
        s.insert(make_pair(cnt[u], u));
      }
    }
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &V[i], &U[i]);
    U[i]--;
    V[i]--;
    g[V[i]].push_back(make_pair(U[i], i));
  }
  int l = 0, r = m;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (solved(mid))
      r = mid;
    else
      l = mid;
  }
  if (solved(r))
    printf("%d", r);
  else
    printf("-1");
}
