#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int n, m;
int a[N], b[N], dd[N];
vector<int> G[N];
int deg[N], id[N], F[N], cnt = 0;
void dfs(int u) {
  dd[u] = 1;
  for (int v : G[u])
    if (!dd[v]) dfs(v);
  id[++cnt] = u;
}
bool check(int mid) {
  for (int i = 1; i <= n; ++i) deg[i] = 0, dd[i] = 0, G[i].clear(), F[i] = 0;
  for (int i = 1; i <= mid; ++i) {
    G[a[i]].push_back(b[i]);
    deg[b[i]]++;
  }
  int st = 0;
  for (int i = 1; i <= n; ++i)
    if (deg[i] == 0) {
      st = i;
      break;
    }
  cnt = 0;
  dfs(st);
  int d = 1;
  F[id[cnt]] = 1;
  for (int i = cnt; i >= 1; i--) {
    int u = id[i];
    for (int v : G[u]) {
      F[v] = max(F[v], F[u] + 1);
      d = max(d, F[v]);
    }
  }
  if (d == n) return true;
  return false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) cin >> a[i] >> b[i];
  int kq = -1, L = 0, R = m;
  while (L <= R) {
    int mid = (L + R) >> 1;
    if (check(mid))
      kq = mid, R = mid - 1;
    else
      L = mid + 1;
  }
  cout << kq;
}
