#include <bits/stdc++.h>
using namespace std;
struct node {
  node() {
    mark = false;
    in = 0;
  }
  bool mark;
  int in;
  vector<int> k;
  vector<int> i;
};
vector<node> a;
vector<int> st;
void dfs(int u, int k) {
  a[u].mark = true;
  for (int i = 0; i < a[u].k.size(); ++i) {
    if (!a[a[u].k[i]].mark && a[u].i[i] < k) {
      dfs(a[u].k[i], k);
    }
  }
  st.push_back(u);
}
bool check_conn(int mid) {
  for (int i = 0; i < st.size() - 1; ++i) {
    int u = st[i], v = st[i + 1];
    bool ok = false;
    for (int j = 0; j < a[u].k.size(); ++j) {
      if (a[u].k[j] == v && a[u].i[j] < mid) {
        ok = true;
      }
    }
    if (!ok) {
      return false;
    }
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  a.resize(n);
  int x, y;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    --x;
    --y;
    a[x].k.push_back(y);
    a[x].i.push_back(i);
    a[y].in++;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i].in == 0) {
      dfs(i, m);
      break;
    }
  }
  reverse(st.begin(), st.end());
  if (st.size() < n || !check_conn(m)) {
    cout << -1;
    return 0;
  }
  int left = n - 1, right = m;
  while (left != right) {
    int mid = (left + right) / 2;
    for (int i = 0; i < n; ++i) {
      a[i].mark = false;
    }
    st.clear();
    for (int i = 0; i < n; ++i) {
      if (a[i].in == 0) {
        dfs(i, mid);
      }
    }
    bool succ = true;
    reverse(st.begin(), st.end());
    if (st.size() < n || !check_conn(mid)) {
      succ = false;
    }
    if (succ) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  cout << left;
  return 0;
}
