#include <stdio.h>
struct job{
int dir;
char name[20];
}a[100005];
int main(){
long long int n,m;
long long int j,k;
int count=0;
scanf("%lld %lld",&n,&m);
for(int i=0;i<n;i++){
scanf("%d %s",&a[i].dir,a[i].name);
}
for(int l=0;l<m;l++){
scanf("%lld %lld",&j,&k);
if(k!=0){
if(a[count].dir==j){
int temp1=count-k;
if(temp1>=0){
count=temp1;
}else{
count=n+temp1;
}
}else{
int temp2=count+k-n;
if(temp2<=0){
count=count+k;
}else{
count=temp2;
}
}
}
}
printf("%s",a[count].name);
}