#include <bits/stdc++.h>
using namespace std;
template <class T>
T maxT(T a, T b) {
  return (a > b ? a : b);
}
template <class T>
T minT(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
void setmax(T &a, T b) {
  a = (a > b ? a : b);
}
template <class T>
void setmin(T &a, T b) {
  a = (a < b ? a : b);
}
void fileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("debug.txt", "w", stderr);
}
void ofileio() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void clock_out() {
  cerr << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const long long MOD = 1000000007;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
long long n, m;
vector<vector<long long>> adj;
vector<bool> vis;
vector<long long> depth;
vector<long long> ord;
void dfs(long long src) {
  ord.push_back(src);
  for (auto nxt : adj[src]) {
    if (!vis[nxt]) {
      vis[nxt] = true;
      setmax(depth[nxt], depth[src] + 1);
      dfs(nxt);
    }
  }
}
void solve() {
  cin >> n >> m;
  adj.resize(n + 1);
  depth.resize(n + 1, 0);
  vis.resize(n + 1, false);
  vector<long long> cnt(n + 1, 0);
  map<pair<long long, long long>, long long> mp;
  for (long long i = 0; i < (long long)m; i++) {
    long long u, v;
    cin >> u >> v;
    mp[{u, v}] = (i + 1);
    adj[u].push_back(v);
    cnt[v]++;
  }
  long long fl = 0, p = -1;
  for (long long i = (long long)1; i < (long long)n + 1; i++) {
    if (cnt[i] == 0) {
      fl++;
      p = i;
    }
  }
  if (fl > 1 || fl == 0) {
    cout << -1;
    return;
  }
  vis[p] = true;
  depth[p] = 1;
  1;
  queue<long long> q;
  q.push(p);
  while (!q.empty()) {
    long long top = q.front();
    q.pop();
    ord.push_back(top);
    long long fl2 = 0;
    for (auto nxt : adj[top]) {
      cnt[nxt]--;
      if (cnt[nxt] == 0) {
        q.push(nxt);
        fl2++;
      }
    }
    if (fl2 > 1) {
      cout << -1;
      return;
    }
  }
  long long ans = 0;
  if ((long long)ord.size() != n) {
    cout << -1;
    return;
  } else {
    for (long long i = 0; i < (long long)ord.size() - 1; i++) {
      ans = max(ans, mp[{ord[i], ord[i + 1]}]);
    }
    cout << ans;
    return;
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  1;
  long long t = 1;
  while (t--) {
    solve();
  }
  1;
  return 0;
}
