#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, x[N], y[N], ind[N];
set<int> st;
vector<vector<int>> v;
inline bool solve(int mid) {
  v.clear();
  v.resize(n + 3);
  st.clear();
  memset(ind, 0, sizeof(ind));
  for (int i = 0; i <= mid; ++i) {
    ++ind[y[i]];
    v[x[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; ++i) {
    if (!ind[i]) st.insert(i);
  }
  while (!st.empty()) {
    if (st.size() > 1) return false;
    int z = *(st.begin());
    st.erase(z);
    for (auto u : v[z]) {
      ind[u]--;
      if (!ind[u]) st.insert(u);
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> x[i] >> y[i];
  }
  int l = 0, r = m - 1, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (solve(mid)) {
      r = mid - 1;
      ans = mid + 1;
    } else
      l = mid + 1;
  }
  cout << ans << "\n";
  return 0;
}
