#include <bits/stdc++.h>
using namespace std;
vector<int> adj[123456], adjj[123456];
vector<pair<int, int> > v;
stack<int> st, stt;
bool see[123456], seee[123456];
int n, m;
void topo(int v, bool see[], stack<int> &st, vector<int> adj[]) {
  see[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    if (see[adj[v][i]] == 0) topo(adj[v][i], see, st, adj);
  }
  st.push(v);
}
inline bool lpath(int a) {
  int mx = 0, mxx = 0;
  memset(see, 0, sizeof see);
  memset(seee, 0, sizeof seee);
  vector<int> dis(n + 1, -123456);
  vector<int> diss(n + 1, -123456);
  dis[a] = 0;
  diss[a] = 0;
  for (int i = 1; i <= n; i++) {
    topo(i, see, st, adj);
    topo(i, seee, stt, adjj);
  }
  while (!st.empty() || !stt.empty()) {
    if (!st.empty()) {
      int u = st.top();
      st.pop();
      if (dis[u] == -123456) continue;
      for (int i = 0; i < adj[u].size(); i++) {
        if (dis[adj[u][i]] < dis[u] + 1) {
          dis[adj[u][i]] = dis[u] + 1;
          mx = max(mx, dis[adj[u][i]]);
        }
      }
    }
    if (!stt.empty()) {
      int u = stt.top();
      stt.pop();
      if (diss[u] == -123456) continue;
      for (int i = 0; i < adjj[u].size(); i++) {
        if (diss[adjj[u][i]] < diss[u] + 1) {
          diss[adjj[u][i]] = diss[u] + 1;
          mxx = max(mxx, diss[adjj[u][i]]);
        }
      }
    }
  }
  if (mx + mxx == n - 1)
    return 1;
  else
    return 0;
}
inline bool can(int x) {
  for (int i = 0; i <= n; i++) {
    adj[i].clear();
    adjj[i].clear();
  }
  for (int i = 0; i < x; i++) {
    adj[v[i].first].push_back(v[i].second);
    adjj[v[i].second].push_back(v[i].first);
  }
  if (lpath(1)) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }
  int l = 1, r = m;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (can(mid)) {
      r = mid;
    } else
      l = mid;
  }
  if (can(l))
    cout << l;
  else if (can(r))
    cout << r;
  else
    cout << -1;
  return 0;
}
