#include<bits/stdc++.h>
using namespace std;
struct toy{
bool cx;
string mz;
}a[100005];
int main(){
//freopen("toy.in","r",stdin);
//freopen("toy.out","w",stdout);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i].cx>>a[i].mz;
}
int q=1;
for(int i=1;i<=m;i++){
bool x;
int y;
cin>>x>>y;
if(a[q].cx==1){
if(x==1){
q-=y;
}else{
q+=y;
q%=10;
}
}else{
if(x==1){
q+=y;
q%=10;
}else{
q-=y;
}
}
if(q<=0){
q+=n;
}
}
cout<<a[q].mz;
return 0;
}