#include<stdio.h>
#include<stdlib.h>
typedef struct node {
int dir;
char name[20];
struct node *front;
struct node *next;
} body;
body *Body,*p,*r,*tt;
int main() {
int n,m,cnt=0;
char temp[100];
scanf("%d%d",&n,&m);
getchar();
for(int i=0; i<n; i++) {
p=(body *)malloc(sizeof(body));
gets(temp);
sscanf(temp,"%d %s",&p->dir,&p->name);
// printf("%d %s",p->dir,p->name);
p->next=NULL;
if(Body==NULL) {
Body=p;
} else {
r->next=p;
p->front=r;
}
r=p;
}
Body->front=r;
r->next=Body;
tt=Body;
int t1,t2;
for(int i=0; i<m; i++) {
scanf("%d%d",&t1,&t2);
if(t1==0) {
if(tt->dir==0) {
while(t2) {
tt=tt->front;
t2--;
}
}
else {
while(t2) {
tt=tt->next;
t2--;
}
}
} else if(t1==1) {
if(tt->dir==0) {
while(t2) {
tt=tt->next;
t2--;
}
}
else {
while(t2) {
tt=tt->front;
t2--;
}
}
}
}
printf("%s",tt->name);
return 0;
}