#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 1000;
vector<int> g[maxN];
pair<int, int> edge[maxN];
int n, m;
int num[maxN];
vector<int> tps;
bool used[maxN];
void dfs(int k) {
  used[k] = true;
  for (int i = 0; i < num[k]; i++) {
    int to = g[k][i];
    if (!used[to]) {
      dfs(to);
    }
  }
  tps.push_back(k);
}
bool f(int k) {
  tps.clear();
  tps.reserve(n + 1);
  for (int i = 1; i <= n; i++) {
    num[i] = 0;
    used[i] = false;
  }
  for (int i = 1; i <= k; i++) {
    num[edge[i].first]++;
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      dfs(i);
    }
  }
  reverse(tps.begin(), tps.end());
  for (int i = 0; i < (int)tps.size() - 1; i++) {
    int u = tps[i];
    int v = tps[i + 1];
    bool t = false;
    for (int i = 0; i < num[u]; i++) {
      int to = g[u][i];
      if (to == v) {
        t = true;
        break;
      }
    }
    if (!t) {
      return false;
    }
  }
  return true;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    edge[i] = make_pair(u, v);
  }
  int r = m + 1;
  int l = 0;
  while (r - l > 1) {
    int m = (r + l) / 2;
    if (f(m)) {
      r = m;
    } else {
      l = m;
    }
  }
  if (r == m + 1) {
    cout << -1 << endl;
  } else {
    cout << r << endl;
  }
  return 0;
}
