#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9 + 7, N = 2e5 + 5, BASE = 129;
long long n, m;
string ans = "";
vector<pair<int, int>> E;
vector<vector<int>> graph;
vector<int> topsort;
bool used[N];
void dfs(int v) {
  used[v] = true;
  for (int u : graph[v]) {
    if (!used[u]) {
      dfs(u);
    }
  }
  topsort.push_back(v);
}
bool check(int k) {
  for (int i = 0; i < n; i++) {
    used[i] = false;
    vector<int> a;
    graph[i] = a;
  }
  while (topsort.size()) {
    topsort.pop_back();
  }
  for (int i = 0; i < k; i++) {
    int go = E[i].first, to = E[i].second;
    graph[go].push_back(to);
  }
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      dfs(i);
    }
  }
  if (topsort.size() < n) {
    return false;
  }
  bool ans = true;
  for (int i = n - 1; i > 0; i--) {
    int v = topsort[i];
    bool if_ = false;
    for (int u : graph[v]) {
      if (u == topsort[i - 1]) {
        if_ = true;
      }
    }
    ans = ans && if_;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  graph.resize(n);
  for (int i = 0; i < m; i++) {
    int go, to;
    cin >> go >> to;
    go--, to--;
    E.push_back(make_pair(go, to));
  }
  int l = 0, r = m;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  if (!check(m)) {
    cout << -1;
  } else {
    cout << r;
  }
}
