#include <bits/stdc++.h>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
pair<int, int> K[100005];
int O[100005], I[100005];
vector<int> P[100005];
int n;
bool funkcja(int x) {
  for (int i = 1; i <= x; i++) {
    P[K[i].first].push_back(K[i].second);
    I[K[i].second]++;
  }
  int s = -1;
  for (int i = 1; i <= n; i++) {
    if (!I[i]) s = i;
  }
  if (s == -1) return 0;
  while (!P[s].empty()) {
    O[s] = 1;
    int r = -1;
    for (auto v : P[s]) {
      I[v]--;
      if (I[v] == 0) r = v;
    }
    if (r == -1) return 0;
    s = r;
  }
  O[s] = 1;
  for (int i = 1; i <= n; i++) {
    if (!O[i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    K[i] = make_pair(a, b);
  }
  int p = 0, k = m + 1;
  while (p + 1 < k) {
    int sr = (p + k) / 2;
    if (funkcja(sr))
      k = sr;
    else
      p = sr;
    for (int i = 1; i <= n; i++) I[i] = 0, O[i] = 0, P[i].clear();
  }
  if (k == m + 1)
    cout << -1;
  else
    cout << k;
  return 0;
}
