#include <iostream> #include <queue> #include <map> #include <set> #include <cmath> #include <cstring> #include <algorithm> #include <iomanip> #include <stack> #include <numeric> #include <ctime> #include <string> #include <bitset> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; const ll N = 1e5 + 5, mod = 1e9 + 7, inf = 2e18; int n, m; void solve() { cin >> n >> m; set<int>st, st2; for (int i = 1; i <= m; i++) { int op, x; cin >> op >> x; if (op == 1) { st.insert(x); if (st.size() >= n || st2.find(x) != st2.end()) { cout << i; return ; } } else { st2.insert(x); if (st2.size() == 2 || st.find(x) != st.end()) { cout << i; return ; } } } cout << -1; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } return 0; }