#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
bool a[200005];
bool check()
{
for(int i=1;i<=n;i++)
{
if(a[i]!=1)
{
return 0;
}
}
return 1;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin>>T;
while(T--)
{
memset(a,0,sizeof(a));
bool flag=0,f=0,fx=0;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int op,x;
cin>>op>>x;
if(flag==1)
{
continue;
}
if(op==1)
{
a[x]=1;
}
else
{
for(int i=1;i<=n;i++)
{
if(i!=x)
{
a[i]=1;
}
}
}
if(check())
{
cout<<i<<endl;
flag=1;
}
}
if(flag==0)
{
cout<<-1<<endl;
}
}
return 0;
}