#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, x[N], y[N], topo[N], in[N];
vector<int> G[N];
bool judge(int cc) {
  memset(in, 0, sizeof(in));
  for (int i = 1; i <= n; ++i) G[i].clear();
  for (int i = 1; i <= cc; ++i) {
    G[x[i]].push_back(y[i]);
    ++in[y[i]];
  }
  int zkx = 0, cnt = 1;
  for (int i = 1; i <= n; ++i)
    if (in[i] == 0 && zkx != 0)
      return false;
    else if (in[i] == 0)
      zkx = i, in[i] = -1;
  while (cnt <= n) {
    int t = 0;
    for (int i = 0; i < G[zkx].size(); ++i) {
      in[G[zkx][i]]--;
      if (in[G[zkx][i]] == 0 && t != 0) return false;
      if (in[G[zkx][i]] == 0) t = G[zkx][i];
    }
    --in[zkx];
    zkx = t;
    ++cnt;
  }
  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;
  while (l < r) {
    int mid = (l + r) / 2;
    if (judge(mid))
      r = mid;
    else
      l = mid + 1;
  }
  if (l == m && !judge(m))
    printf("-1");
  else
    printf("%d", l);
  return 0;
}
