#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const int MAXN = 200001;
vector<int> e[MAXN];
int c[MAXN];
set<int> nl;
bool w[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  int an = 0;
  for (int i = 1; i <= n; i++) nl.insert(i), c[i] = 0, w[i] = false;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (w[u]) continue;
    e[u].push_back(v);
    if (c[v]++ == 0) nl.erase(v);
    while (nl.size() == 1) {
      int cr = *nl.begin();
      w[cr] = true;
      nl.clear();
      an++;
      for (int i = 0; i < e[cr].size(); i++) {
        if (--c[e[cr][i]] == 0) nl.insert(e[cr][i]);
      }
    }
    if (an == n) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
