#include<bits/stdc++.h>
#define max_size 11
using namespace std;
int main()
{
int n=0,m=0;
bool towards[100005];
char a[100005][max_size];
int location=1;
int temp_lo=0,num=0;
cin >> n >> m;
for(int i=1;i<=n;i++){
cin >> towards[i] >> a[i];
}
for(int i=0;i<m;i++){
cin >> temp_lo >> num;
if(towards[location]^temp_lo){
location+=num;
if(location>n){
location-=n;
}
}
else{
location-=num;
if(location<0){
location+=n;
}
}
}
cout << a[location];
}