#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> ans;
vector<bool> used;
void dfs(int v) {
  used[v] = true;
  for (auto u : g[v]) {
    if (!used[u]) {
      dfs(u);
    }
  }
  ans.push_back(v);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> u(m);
  vector<int> v(m);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
    g[u[i]].push_back(v[i]);
  }
  used.resize(n);
  for (int i = 0; i < n; ++i) {
    used[i] = false;
  }
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      dfs(i);
    }
  }
  reverse(ans.begin(), ans.end());
  vector<int> pos(n);
  for (int i = 0; i < n; ++i) {
    pos[ans[i]] = i;
  }
  int cnt = 0;
  for (int i = 0; i < m; ++i) {
    if (pos[u[i]] != n - 1) {
      if (ans[pos[u[i]] + 1] == v[i]) {
        cnt++;
      }
    }
    if (cnt == n - 1) {
      cout << i + 1 << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
