#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int u[N], v[N], cnt[N], vis[N];
vector<int> g[N];
int dfs(int u) {
  if (cnt[u] != -1) {
    return cnt[u];
  }
  int x = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    x = max(x, dfs(g[u][i]));
  }
  cnt[u] = x + 1;
  return cnt[u];
}
bool ok(int x, int n) {
  for (int i = 1; i <= n; i++) {
    g[i].clear();
    cnt[i] = -1;
    vis[i] = 0;
  }
  for (int i = 0; i < x; i++) {
    g[u[i]].push_back(v[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] == -1) {
      dfs(i);
    }
  }
  int ret = 0;
  bool dis = true;
  for (int i = 1; i <= n; i++) {
    ret += (cnt[i] == 1);
    if (vis[cnt[i]]) {
      dis = false;
    }
    vis[cnt[i]] = true;
  }
  return dis && (ret == 1);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", u + i, v + i);
  }
  int lo = 0, hi = m, mid;
  while (hi - lo > 1) {
    mid = (lo + hi) >> 1;
    if (ok(mid, n)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (ok(hi, n)) {
    printf("%d\n", hi);
  } else {
    puts("-1");
  }
  return 0;
}
