#include <bits/stdc++.h>
using namespace std;
bool dead[100500];
set<int> loosers;
int a[100500];
vector<int> e[100500];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int loosers_count = n;
  for (int i = 0; i < n; i++) loosers.insert(i + 1);
  for (int q = 0; q < m; q++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (dead[u] || dead[v]) continue;
    if (a[u] == 0) {
      loosers_count--;
      loosers.erase(loosers.find(u));
    }
    a[u]++;
    e[v].push_back(u);
    while (loosers_count == 1) {
      int curr = *(loosers.begin());
      loosers.erase(loosers.begin());
      loosers_count--;
      dead[curr] = true;
      n--;
      if (n == 1) {
        cout << q + 1 << endl;
        return 0;
      }
      for (int i = 0; i < e[curr].size(); i++) {
        int win = e[curr][i];
        a[win]--;
        if (a[win] == 0) {
          loosers.insert(win);
          loosers_count++;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
