#include<bits/stdc++.h>
using namespace std;
struct node{
int x;
string name;
}a[1000005];
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].name;
int now=1;
while(m--)
{
int x,s;
cin>>x>>s;
if(x==0 and a[now].x==0) now=(now+n-s)%n;
else if(x==0 and a[now].x==1) now=(now+s)%n;
else if(x==1 and a[now].x==0) now=(now+s)%n;
else now=(now+n-s)%n;
}
cout<<a[now].name<<endl;
return 0;
}