#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e9 + 19;
int n, m;
vector<pair<int, int> > edge;
vector<int> e[N];
bool use[N];
vector<int> st;
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    edge.push_back(make_pair(v, u));
  }
}
void dfs(int v) {
  use[v] = 1;
  for (auto u : e[v])
    if (!use[u]) dfs(u);
  st.push_back(v);
}
bool check(int k) {
  for (int i = 0; i < n; i++) e[i].clear();
  for (int i = 0; i < k; i++) e[edge[i].first].push_back(edge[i].second);
  memset(use, 0, sizeof(use));
  st.clear();
  for (int i = 0; i < n; i++)
    if (!use[i]) dfs(i);
  reverse(st.begin(), st.end());
  for (int i = 0; i < n - 1; i++) {
    int v = st[i];
    int u = st[i + 1];
    bool flag = 0;
    for (auto y : e[v])
      if (y == u) flag = 1;
    if (!flag) return 0;
  }
  return 1;
}
void solve() {
  if (!check(m)) {
    puts("-1");
    return;
  }
  int l = 0;
  int r = m;
  while (r - l > 1) {
    if (check((l + r) / 2))
      r = (l + r) / 2;
    else
      l = (l + r) / 2;
  }
  printf("%d\n", r);
}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
    }
  } else {
    stress();
  }
  return 0;
}
