#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<stdio.h>
#include<queue>
#include<iomanip>
#include<string>
#include<cstdio>
using namespace std;
struct Node{
bool toward;
string name;
}ZhoumyCode[100001];
int main(){
int n,m,a,much,now=1;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>ZhoumyCode[i].toward>>ZhoumyCode[i].name;
}
for(int i=1;i<=m;i++){
cin>>a>>much;
much%n;
if(a==1){//右
if(ZhoumyCode[now].toward==1) now=now-much;//朝外
else now=now+much;//朝内
}
else{//左
if(ZhoumyCode[now].toward==1) now=now+much;//朝外
else now=now-much;//朝内
}
if(now>m)now=now%n;
if(now<0){
now=now+n*10;
now=now%n;
}
}
cout<<ZhoumyCode[now].name;
return 0;
}