#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, x[N], y[N], num[N], val[N], dp[2][N], cnt;
vector<int> adj[N];
bool vis[N];
void DFS(int u) {
  vis[u] = true;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    if (vis[v] == false) DFS(v);
  }
  num[u] = cnt;
  val[cnt--] = u;
}
bool Check(int k) {
  for (int i = 1; i <= n; ++i) adj[i].clear();
  for (int i = 1; i <= k; ++i) adj[x[i]].push_back(y[i]);
  for (int i = 1; i <= n; ++i) num[i] = 0, vis[i] = false;
  cnt = n;
  for (int i = 1; i <= n; ++i)
    if (vis[i] == false) DFS(i);
  memset(dp, 0, sizeof dp);
  for (int u = 1; u <= n; ++u) {
    for (int i = 0; i < (int)adj[val[u]].size(); ++i) {
      int v = adj[val[u]][i];
      dp[0][v] = max(dp[0][v], dp[0][val[u]] + 1);
    }
  }
  for (int u = n; u >= 1; --u) {
    for (int i = 0; i < (int)adj[val[u]].size(); ++i) {
      int v = adj[val[u]][i];
      dp[1][val[u]] = max(dp[1][val[u]], dp[1][v] + 1);
    }
  }
  for (int i = 1; i <= n; ++i)
    if (dp[0][i] + 1 + dp[1][i] != n) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &x[i], &y[i]);
  int l = 1, r = m, res = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (Check(mid)) {
      res = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%d", res);
  return 0;
}
