#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
struct node
{
int l;
string ss;
}a[100006];
int fx[100006],s[100006];
int n,m;
int ans;
int main()
{
freopen("toya.in","r",stdin);
freopen("toya.out","w",stdout);
int i;
cin>>n>>m;
for (i=1;i<=n;i++)
{
cin>>a[i-1].l;
cin>>a[i-1].ss;
}
ans=0;
for (i=1;i<=m;i++)
{
cin>>fx[i];
cin>>s[i];
if (a[ans].l==0)
{
if (fx[i]==0) ans=(ans-s[i]+n)%n;
else if (fx[i]==1) ans=(ans+s[i])%n;
}
else if (a[ans].l==1)
{
if (fx[i]==0) ans=(ans+s[i])%n;
else if (fx[i]==1) ans=(ans-s[i]+n)%n;
}
}
cout<<a[ans].ss;
return 0;
}