#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
vector<vector<int>> g;
vector<vector<int>> id;
vector<int> used;
vector<int> ts;
void dfs(int v, int x) {
  if (used[v]) return;
  used[v] = 1;
  for (int i = 0; i < (int)g[v].size(); i++) {
    if (id[v][i] < x) {
      dfs(g[v][i], x);
    }
  }
  ts.push_back(v);
}
bool check(int x) {
  ts.clear();
  used = vector<int>(g.size());
  for (int i = 0; i < (int)g.size(); i++) {
    dfs(i, x);
  }
  reverse(ts.begin(), ts.end());
  for (int i = 0; i + 1 < (int)ts.size(); i++) {
    int v = ts[i];
    bool ok = false;
    for (int j = 0; j < (int)g[v].size(); j++)
      if (g[v][j] == ts[i + 1] && id[v][j] < x) {
        ok = true;
      }
    if (!ok) return false;
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  g = vector<vector<int>>(n);
  id = vector<vector<int>>(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a].push_back(b);
    id[a].push_back(i);
  }
  if (!check(m)) {
    printf("-1\n");
    return 0;
  }
  int l = 0;
  int r = m;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\n", r);
  return 0;
}
