#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > adj[2];
int pos[100009] = {0};
bool vis[100009] = {0};
int indx = 0, range = 0;
bool DFS(int i) {
  if (vis[i]) return 1;
  vis[i] = 1;
  int cnt = 0;
  bool s = 1;
  for (auto j : adj[indx][i]) {
    int node = j.first;
    if (j.second > range) break;
    if (pos[node] == -1) s &= DFS(node);
  }
  if (!s) return 0;
  for (auto j : adj[indx][i])
    if (j.second > range)
      break;
    else {
      cnt += (pos[j.first] == -1);
      pos[j.first] = i;
    }
  if (cnt > 1) return 0;
  return 1;
}
int main() {
  int n = 0, m = 0, ans = -1;
  cin >> n >> m;
  adj[0].resize(100009);
  adj[1].resize(100009);
  for (int i = 1; i <= m; i++) {
    int a = 0, b = 0;
    cin >> a >> b;
    adj[0][a].push_back(make_pair(b, i));
    adj[1][b].push_back(make_pair(a, i));
  }
  int l = 1, r = m;
  while (l <= r) {
    int mid = (l + r) / 2;
    range = mid;
    bool s[5] = {1, 1, 1, 1, 1};
    int e[5] = {0, 0, 0, 0, 0};
    for (indx = 0; indx < 2; indx++) {
      memset(pos, -1, sizeof pos);
      memset(vis, 0, sizeof vis);
      for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        s[indx] &= DFS(i);
      }
      for (int i = 1; i <= n; i++) e[indx] += (pos[i] != -1);
    }
    if (s[0] && e[0] == n - 1 && s[1] && e[1] == n - 1)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}
