#include <bits/stdc++.h>
using namespace std;
template <typename T>
T input() {
  T ans = 0, m = 1;
  char c = ' ';
  while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
  if (c == '-') m = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + (c - '0'), c = getchar();
  }
  return ans * m;
}
template <typename T>
void read(T& a) {
  a = input<T>();
}
template <typename T, typename... R>
void read(T& a, R&... r) {
  a = input<T>();
  read(r...);
}
int n, m;
const int M = 1e5 + 10;
const int N = 1e5 + 10;
int x[M], y[M];
vector<int> g[N];
vector<int> ts;
bool u[N];
void dfs(int v) {
  u[v] = 1;
  for (auto to : g[v]) {
    if (!u[to]) dfs(to);
  }
  ts.push_back(v);
}
bool can(int mid) {
  for (int i = 0; i < n; ++i) {
    g[i].clear();
    u[i] = 0;
  }
  ts.clear();
  int f[n], sz[n];
  int top, ok = 0;
  memset(f, 0, sizeof(f));
  memset(sz, 0, sizeof(sz));
  for (int i = 0; i <= mid; ++i) {
    g[x[i]].push_back(y[i]);
    sz[y[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    if (!sz[i]) {
      top = i;
      ++ok;
    }
  }
  if (ok == 1) {
    dfs(top);
  } else
    return 0;
  for (auto i : ts) {
    for (auto to : g[i]) {
      f[i] = max(f[i], f[to] + 1);
    }
  }
  return f[top] == n - 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  read(n, m);
  for (int i = 0; i < m; ++i) {
    read(x[i], y[i]);
    x[i]--, y[i]--;
  }
  int l = 0, r = m - 1;
  while (l < r) {
    int mid = (l + r) / 2;
    if (can(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  if (can(l))
    cout << l + 1 << endl;
  else
    cout << -1 << endl;
}
