#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 1e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
using namespace std;
int n, m;
vector<pair<int, int> > e;
bool Check(int k) {
  vector<bool> rem(n + 1, false);
  vector<int> in[n + 1], out[n + 1], rank(n + 1, -1);
  for (int i = 0; i <= k; i++) {
    in[e[i].second].push_back(e[i].first);
    out[e[i].first].push_back(e[i].second);
  }
  int cnt_in = 0, cnt_out = 0, one = -1, last = -1;
  for (int i = 1; i <= n; i++) {
    if ((int)in[i].size() == 0) {
      cnt_in++;
      one = i;
    }
    if ((int)out[i].size() == 0) {
      cnt_out++;
      last = i;
    }
  }
  if (cnt_in * cnt_out != 1) return false;
  rank[1] = one;
  rank[n] = last;
  int cur = one;
  for (int i = 2; i <= n; i++) {
    int fone = 0, nxt = -1;
    for (auto u : out[cur]) {
      int cnt = 0;
      for (auto t : in[u]) {
        if (rem[t] == false) cnt++;
      }
      if (cnt == 1) {
        fone++;
        nxt = u;
      }
    }
    if (fone != 1)
      return false;
    else {
      rem[cur] = true;
      cur = nxt;
      rank[i] = cur;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (rank[i] == -1) return false;
  }
  return true;
}
void TestCase() {
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    e.push_back({u, v});
  }
  int lb = 0, ub = m - 1, ans = m;
  while (lb <= ub) {
    int mid = (lb + ub) / 2;
    if (Check(mid)) {
      ans = min(ans, mid);
      ub = mid - 1;
    } else
      lb = mid + 1;
  }
  ans == m ? cout << -1 : cout << ans + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T = 1;
  while (T--) {
    TestCase();
  }
  return 0;
}
