//洛谷P1563 [NOIP2016 提高组] 玩具谜题
//原题链接
https://www.luogu.com.cn/problem/P1563
#include
#include
using namespace std;
int toward[100005];
string name[100005];
int len,n,lr,step,pos;
int main()
{
cin>>len>>n;
for(int i=0;i<len;i++)
{
cin>>toward[i];
cin>>name[i];
}
for(int i=1;i<=n;i++)
{
cin>>lr>>step;
if(lr==0)
{
if(toward[pos]==0)
{
if(pos<step) pos+=len;
pos-=step;
}
else pos=(pos+step)%len;
}
else
{
if(toward[pos]==0) pos=(pos+step)%len; //1.第一次把%写成了&,WA了9个点
else
{
{
if(pos<step) pos+=len;
pos-=step;
}
}
}
}
cout<<name[pos]<<endl;
return 0;
}
//注意使用正确的语法形式