#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long z = 1000000000;
const long long N = 1e5 + 1;
const long long INF = 1e18;
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long n, m, k, t;
vector<pair<long long, long long>> a, temp;
vector<vector<long long>> adj;
vector<long long> dp;
stack<long long> s;
void topo_dfs(long long start, vector<bool> &vis) {
  vis[start] = true;
  for (long long u : adj[start]) {
    if (vis[u] == false) {
      topo_dfs(u, vis);
    }
    dp[start] = max(dp[start], dp[u] + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    a.push_back(make_pair(u, v));
  }
  long long low = 0, high = m;
  long long ans = -1;
  dp.resize(n);
  while (low <= high) {
    long long mid = (low + high) / 2;
    temp.clear();
    for (long long i = 0; i < n; i++) dp[i] = 1;
    for (long long i = 0; i < mid; i++) {
      temp.push_back(a[i]);
    }
    adj.clear();
    adj.resize(n);
    for (long long i = 0; i < temp.size(); i++) {
      adj[temp[i].first].push_back(temp[i].second);
    }
    vector<bool> vis(n, false);
    for (long long i = 0; i < n; i++) {
      if (vis[i] == false) topo_dfs(i, vis);
    }
    long long maxlen = 0;
    for (long long i = 0; i < n; i++) {
      maxlen = max(maxlen, dp[i]);
    }
    if (maxlen >= n) {
      high = mid - 1;
      ans = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << ans;
}
