#include<stdio.h>
struct DATA
{
char job[12];
int ps;
}people[100005];
int main()
{
long long n,m,i,k,zlp;
int zlf;
freopen("toya.in","r",stdin);
freopen("toya.out","w",stdout);
scanf("%lld %lld",&n,&m);
for (i=1;i<=n;i++) scanf("%d %s",&people[i].ps,&people[i].job);
k=1;
for (i=1;i<=m;i++)
{
scanf("%d %lld",&zlf,&zlp);
if (zlf==0)
{
if (people[k].ps==0)
{
k-=zlp;
if (k<=0) k=n+k;
}
else if (people[k].ps==1)
{
k+=zlp;
if (k>n) k-=n;
}
}
else if (zlf==1)
{
if (people[k].ps==0)
{
k+=zlp;
if (k>n) k-=n;
}
else if (people[k].ps==1)
{
k-=zlp;
if (k<=0) k=n+k;
}
}
}
printf("%s",people[k].job);
fclose(stdin);
fclose(stdout);
return 0;
}