#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
int tests = 1;
int n, m, k;
int a[N];
vector<int> g[N], order;
bool u[N];
int dp[N];
int x[N], y[N];
inline void _clear() {
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    u[i] = 0;
    g[i].clear();
  }
}
void dfs(int v) {
  u[v] = 1;
  for (int to : g[v]) {
    if (!u[to]) dfs(to);
  }
  order.push_back(v);
}
inline void Solve() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
  }
  int l = 1, r = m, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    _clear();
    for (int i = 1; i <= mid; i++) g[x[i]].push_back(y[i]);
    for (int i = 1; i <= n; i++)
      if (!u[i]) dfs(i);
    reverse(order.begin(), order.end());
    for (int v : order) {
      for (int to : g[v]) {
        dp[to] = max(dp[to], dp[v] + 1);
      }
    }
    bool ok = 1;
    for (int i = 1; i <= n; i++) {
      if (dp[order[i - 1]] != i) {
        ok = 0;
      }
    }
    if (ok) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  while (tests--) {
    Solve();
  }
  return 0;
}
