#include <bits/stdc++.h>
using namespace std;
long long int P = 998244353;
long long int dp[100001], res[100001];
vector<pair<long long int, long long int>> adj[100001];
long long int vis[100001];
long long int ans = 0;
long long int no;
long long int dfs(long long int u) {
  if (!vis[u]) {
    vis[u] = 1;
    dp[u] = 1;
  }
  for (auto v : adj[u]) {
    long long int n = v.first;
    if (!vis[n] && v.second <= no) {
      if (dfs(n) + 1 > dp[u]) {
        dp[u] = max(dp[u], dp[n] + 1);
        res[u] = max(res[n], v.second);
      }
    }
    if (dp[n] + 1 > dp[u] && v.second <= no) {
      dp[u] = max(dp[u], dp[n] + 1);
      res[u] = max(res[n], v.second);
    }
  }
  return (ans = max(ans, dp[u]));
}
void solve() {
  long long int i, j, k, l, m, n, o, p, q, r;
  cin >> n >> m;
  set<long long int> ind, outd;
  for (i = 1; i <= n; i++) {
    ind.insert(i);
    outd.insert(i);
  }
  memset(vis, 0, sizeof(vis));
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    adj[j].push_back({k, i + 1});
    ind.erase(k);
    outd.erase(j);
  }
  if (ind.size() != 1 || outd.size() != 1) {
    cout << "-1\n";
    return;
  }
  long long int u = *ind.begin();
  long long int start = 1, end = m;
  r = 0;
  long long int an = -1;
  while (start <= end) {
    long long int mid = (start + end) / 2;
    no = mid;
    ans = 0;
    memset(vis, 0, sizeof(vis));
    memset(dp, 0, sizeof(dp));
    memset(res, 0, sizeof(res));
    dfs(u);
    if (ans == n) {
      an = mid;
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  cout << an << endl;
}
int main() {
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
