#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
string zh[100005];
int a[100005],s[100005],ch[100005];
int n,m,i,ans=1,t;
using namespace std;
int main()
{
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)//输入情况
cin>>ch[i]>>zh[i];
for(i=1;i<=m;i++)//输入指令
{
scanf("%d %d",&a[i],&s[i]);//方向和路程
if(a[i]==0&&ch[ans]==0)
ans=(ans+n-s[i])%n;
else if(a[i]==1&&ch[ans]==1)
ans=(ans+n-s[i])%n;
else
ans=(ans+s[i])%n;
}
cout<<zh[ans];
return 0;