#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
const int inf = 1e9;
const int md = 1e9 + 7;
vector<pair<int, int> > edges;
int n, m;
bool solve(int mid) {
  if (mid < 0) return false;
  vector<vector<int> > g(n);
  set<pair<int, int> > st;
  vector<int> st_a(n);
  for (int i = 0; i <= mid; ++i) {
    g[edges[i].first].push_back(edges[i].second);
    st_a[edges[i].second]++;
  }
  int cnt_zero = 0;
  for (int i = 0; i < n; ++i) {
    st.insert(make_pair(st_a[i], i));
    if (g[i].size() == 0) ++cnt_zero;
  }
  for (int i = 0; i < n; ++i) {
    if (cnt_zero != 1) return false;
    auto tmp = *st.begin();
    st.erase(tmp);
    --cnt_zero;
    int v = tmp.second;
    for (auto u : g[v]) {
      auto tmp2 = st.find(make_pair(st_a[u], u));
      st.erase(tmp2);
      --st_a[u];
      st.insert(make_pair(st_a[u], u));
      if (st_a[u] == 0) ++cnt_zero;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edges.push_back({u, v});
  }
  int l = 0, r = m;
  while (l < r) {
    int mid = (l + r) / 2;
    if (solve(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l + 1 > m) {
    cout << -1 << endl;
  } else {
    cout << l + 1 << endl;
  }
  return 0;
}
