#include <bits/stdc++.h>
using namespace std;
const long long int maxa = 10000000000000ll;
const int maxn = 1e5 + 5;
const int N = 1e6;
bool vis[maxn];
vector<int> v1;
int u[maxn], v[maxn], dp[maxn];
vector<int> g[maxn];
void dfs(int u) {
  vis[u] = true;
  for (int i = 0; i < g[u].size(); i++) {
    if (!vis[g[u][i]]) dfs(g[u][i]);
  }
  v1.push_back(u);
}
int n;
bool check(int mid) {
  int i, j;
  for (i = 0; i < n; i++) g[i].clear();
  for (i = 0; i < mid; i++) g[u[i]].push_back(v[i]);
  v1.clear();
  memset(vis, false, sizeof(vis));
  for (i = 0; i < n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(dp, 0, sizeof(dp));
  for (i = 0; i < v1.size(); i++) {
    dp[v1[i]] = 1;
    for (j = 0; j < g[v1[i]].size(); j++)
      dp[v1[i]] = max(dp[v1[i]], 1 + dp[g[v1[i]][j]]);
  }
  return dp[v1.back()] == n;
}
int main() {
  int m, i;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> u[i] >> v[i];
    u[i]--;
    v[i]--;
  }
  int l = -1;
  int r = m + 1;
  while (r - l > 1) {
    int mid = l + (r - l) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  if (r == m + 1) r = -1;
  cout << r << endl;
  return 0;
}
