#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 1;
long long n, m;
vector<long long> topo, vis;
vector<vector<long long> > adj;
pair<long long, long long> e[N];
void dfs(long long cur) {
  vis[cur] = 1;
  for (long long i : adj[cur])
    if (!vis[i]) dfs(i);
  topo.push_back(cur);
}
bool check(long long x) {
  adj.clear();
  topo.clear();
  adj.resize(N);
  vis.assign(N, 0);
  map<pair<long long, long long>, bool> mp;
  for (long long i = (1); i <= (x); i++)
    adj[e[i].second].push_back(e[i].first), mp[{e[i].second, e[i].first}] = 1;
  for (long long i = (1); i <= (n); i++)
    if (!vis[i]) dfs(i);
  reverse(topo.begin(), topo.end());
  for (long long i = (1); i <= (topo.size() - 1); i++)
    if (!mp[{topo[i - 1], topo[i]}]) return false;
  return true;
}
long long search(long long start, long long end) {
  if (start == end) return start;
  long long mid = (start + end) / 2;
  if (check(mid))
    return search(start, mid);
  else
    return search(mid + 1, end);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = (1); i <= (m); i++) cin >> e[i].first >> e[i].second;
  if (!check(m))
    cout << -1;
  else
    cout << search(1, m);
}
