#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = 3.14159265358979323846;
const long double gammama = 0.57721566490153286060;
const long double eps = 1e-5;
const int INF = 1000 * 1000 * 1000 + 1;
const long long LINF = (long long)1000 * 1000 * 1000 * 1000 * 1000 * 1000;
const long long mod = 1000 * 1000 * 1000 + 7;
const long long N = 5000 + 100;
int n, m;
vector<pair<int, int> > ed;
vector<vector<int> > g;
vector<int> used;
vector<int> order;
void dfs(int pos) {
  used[pos] = 1;
  for (int i = 0; i < g[pos].size(); ++i) {
    int to = g[pos][i];
    if (used[to]) continue;
    dfs(to);
  }
  order.push_back(pos);
}
bool f(int x) {
  g.clear();
  g.resize(n);
  for (int i = 0; i < x; ++i) {
    g[ed[i].first].push_back(ed[i].second);
  }
  used.assign(n, 0);
  order.clear();
  for (int i = 0; i < n; ++i) {
    if (!used[i]) dfs(i);
  }
  for (int i = 1; i < n; ++i) {
    int v = order[i];
    bool ok = 0;
    for (int j = 0; j < g[v].size(); ++j) {
      if (g[v][j] == order[i - 1]) {
        ok = 1;
        break;
      }
    }
    if (!ok) return 0;
  }
  return 1;
}
void solve() {
  cin >> n >> m;
  ed.resize(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    ed[i] = pair<int, int>(b, a);
  }
  if (!f(m)) {
    cout << -1 << endl;
    return;
  }
  int low = 0, up = m;
  while (up - low > 1) {
    int mid = (up + low) / 2;
    if (f(mid)) {
      up = mid;
    } else
      low = mid;
  }
  cout << up << endl;
}
int main() {
  solve();
  return 0;
}
