#include<iostream>
using namespace std;
int main()
{
int direction[10000];
char name[100000][11];
int n, m;//n:小人个数 m:指令个数
int a, s;//a: 左右方向 s:左右距离
int i;
int position;
position = 0;
cin >> n >> m;
for(i = 0; i < n; i++)
{
cin >> direction[i] >> name[i];
}
for(i = 0; i < m; i++)
{
cin >> a >> s;
if(direction[position] + a == 1)
{
position = (position + s) % n;
}
else
{
position = (position - s + n) % n;
}
}
cout << name[position] << endl;
}