#include <bits/stdc++.h>
using namespace std;
int const MAX_N = 200100;
int n, m, num;
int x[MAX_N], y[MAX_N], nnew[MAX_N], lst[MAX_N], real_index[MAX_N];
vector<int> e[MAX_N], back_e[MAX_N];
void dfs(int v, int qq) {
  nnew[v] = 1;
  int i;
  if (qq >= 0)
    for (int j = 0; j < (int)e[v].size(); j++) {
      i = e[v][j];
      if (nnew[i] == 0) dfs(i, qq + 1);
    }
  lst[num] = v;
  num--;
  nnew[v] = 2;
}
int poss_cnt(int Q) {
  Q = min(Q, m);
  for (int i = 0; i <= n; i++) {
    e[i].clear();
    back_e[i].clear();
  }
  for (int j = 0; j < Q; j++) {
    e[x[j]].push_back(y[j]);
    back_e[y[j]].push_back(x[j]);
  }
  num = n;
  for (int i = 1; i <= n; i++) nnew[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!nnew[i]) dfs(i, 1);
  for (int i = 1; i <= n; i++) real_index[lst[i]] = i;
  for (int i = 1; i <= n; i++) {
    int v = lst[i];
    int mx_ind = -10;
    for (int j = 0; j < (int)back_e[v].size(); j++) {
      int old_v = back_e[v][j];
      mx_ind = max(mx_ind, real_index[old_v]);
    }
    if (mx_ind < 0 && i == 1) continue;
    if (i <= mx_ind + 1) continue;
    return 2;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &x[i], &y[i]);
  int down = 0, up = m + 1;
  while (up > down) {
    int mid = (up + down) / 2;
    if (poss_cnt(mid) <= 1LL)
      up = mid;
    else
      down = mid + 1;
  }
  if (poss_cnt(down) >= 2LL) {
    cout << "-1";
    return 0;
  }
  cout << down;
  return 0;
}
