#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x7fffffff;
const long long linf = ~(1LL << 63);
template <typename T>
inline T gcd(T a, T b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename C>
inline void sort(C& v) {
  sort(v.begin(), v.end());
}
inline void println(int u) { printf("%d\n", u); }
inline void printsp(int u) { printf("%d ", u); }
const int maxn = 100050;
int d[maxn];
vector<int> E[maxn];
int order[maxn];
vector<int> ord;
vector<int> ord2;
bool vis[maxn];
void dfs2(int x) {
  vis[x] = true;
  for (int i = E[x].size() - 1; i >= 0; i--) {
    int to = E[x][i];
    if (!vis[to]) dfs2(to);
  }
  ord2.push_back(x);
}
void dfs(int x) {
  vis[x] = true;
  for (int i = 0; i < E[x].size(); i++) {
    int to = E[x][i];
    if (!vis[to]) dfs(to);
  }
  ord.push_back(x);
}
bool topological_sort(int x) {
  memset(vis, 0, sizeof vis);
  dfs(x);
  memset(vis, 0, sizeof vis);
  dfs2(x);
  for (int i = 0; i < ord.size(); i++) {
    if (ord[i] != ord2[i]) return false;
    order[ord[i]] = i;
  }
  return true;
}
int edu[maxn], edv[maxn];
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
    edu[i] = u;
    edv[i] = v;
    d[v]++;
  }
  int u, cnt = 0;
  for (int i = 1; i <= n; i++)
    if (d[i] == 0) {
      u = i;
      cnt++;
    }
  bool can = true;
  if (cnt != 1)
    can = false;
  else {
    can = topological_sort(u);
  }
  if (!can) {
    cout << -1 << endl;
  } else {
    int ans = m;
    for (int i = ans - 1; i >= 0; i--) {
      if (abs(order[edu[i]] - order[edv[i]]) == 1) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
