#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > M;
int A[100010];
vector<int> B;
vector<pair<pair<int, int>, int> > W;
int pp(int l, int r, const pair<int, int>& q) {
  int m = (l + r) / 2;
  if (W[m].first == q) return W[m].second;
  if (W[m].first > q) return pp(l, m - 1, q);
  if (W[m].first < q) return pp(m + 1, r, q);
}
int main() {
  int i, j, m, n, k;
  scanf("%d%d", &n, &m);
  M.assign(n, vector<int>());
  W.clear();
  memset(A, 0, sizeof(A));
  for (i = 0; i < m; i++) {
    scanf("%d%d", &j, &k);
    W.push_back(make_pair(make_pair(k - 1, j - 1), i + 1));
    M[k - 1].push_back(j - 1);
    A[j - 1]++;
  }
  j = -1;
  sort(W.begin(), W.end());
  for (i = 0; i < n; i++)
    if (A[i] == 0) {
      if (j != -1) {
        printf("-1\n");
        return 0;
      }
      j = i;
    }
  B.clear();
  for (i = 0; i < n; i++) {
    B.push_back(j);
    int j1 = -1;
    for (k = 0; k < M[j].size(); k++) {
      A[M[j][k]]--;
      if (A[M[j][k]] == 0) {
        if (j1 != -1) {
          printf("-1\n");
          return 0;
        }
        j1 = M[j][k];
      }
    }
    j = j1;
  }
  int ans = 0;
  for (i = 0; i < B.size() - 1; i++) {
    ans = max(ans, pp(0, W.size() - 1, make_pair(B[i], B[i + 1])));
  }
  printf("%d\n", ans);
  return 0;
}
