#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const double EPS = 1e-8;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
const int MAXN = 100100;
vector<int> adj[MAXN];
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> ind(n, 0);
  vector<pair<int, int> > edges;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    ind[v]++;
    edges.emplace_back(u, v);
  }
  queue<int> q;
  for (int i = 0; i < n; i++)
    if (ind[i] == 0) q.push(i);
  vector<int> pos(n);
  int id = 0;
  while (!q.empty()) {
    if ((int)q.size() != 1) {
      cout << -1 << endl;
      return 0;
    }
    int u = q.front();
    q.pop();
    pos[u] = id++;
    for (int v : adj[u]) {
      ind[v]--;
      if (ind[v] == 0) q.push(v);
    }
  }
  int tot = 0;
  for (int i = 0; i < m; i++) {
    pair<int, int> p = edges[i];
    if (pos[p.first] + 1 == pos[p.second]) tot++;
    if (tot == n - 1) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  assert(false);
  return 0;
}
