// #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
bool a[static_cast<int>(1e5 + 10)];//--------a【i】 == 1表示第i+1个框有石子
void yes(int T){//-----------单纯为了少打一点字,不过会降低可读性。
cout << T;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
int t, x, T = 1;
int size = 0;
while(m--){
cin >> t >> x;
if (t == 2) {//----------操作2
if (a[x - 1]){yes(T);return 0;}//---------如果当前这个有石子,结束
else {
memset(a, 1, sizeof(a));//----------把所有框框标记为有石子
size = n - 1;
a[x - 1] = 0;//--------除了当前这个
}
}
else {//-------操作1
if (size == n - 1 && a[x - 1] == false) {yes(T); return 0;}//---------如果有石子的框的个数为n-1,且当前框没石子
if (!a[x - 1]) size++;//------维护有石子的框的个数
a[x - 1] = 1; //-----------更新状态
}
T++;
}
cout << -1;
return 0;
}
// 64 位输出请用 printf("%lld")