#include <iostream>
#include <string>
#include <cstring>
#define N 100000+10
using namespace std;
typedef struct people{
int direction;
char name[10];
}P;
int main(int argc, char** argv) {
int n,m,a,s;
P p[N];
cin >> n >> m;
for(int i = 0 ;i < n; i++ )
{
cin >> p[i].direction;
cin >> p[i].name;
}
int now = 0;
for(int i = 1; i <= m ; i++)
{
cin >> a >> s;
if(a == 0 && p[now].direction == 0) now = (n+now-s)%n;
else if(a == 0 && p[now].direction == 1) now = (now+s)%n;
else if(a == 1 && p[now].direction == 0 ) now = (now+s)%n;
else if(a == 1 && p[now].direction == 1) now = (n+now-s)%n;
}
cout << p[now].name<<endl;
return 0;
}