#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int n, m;
int p[200000];//存方向
int q[200000];//存移动个数
int location=1;
struct peo {
int direct;
string profession;
}people[200000];
void caozuo(int p, int q) {
if (people[location].direct == 1) {
if (p == 1) {
if (location - q <= 0) {
location = location + n - q;
}
else {
location -= q;
}
}
else {
location = abs((location + q) % n);
}
}
else if (people[location].direct == 0) {
if (p == 0) {
if (location - q <= 0) {
location = location + n - q;
}
else {
location -= q;
}
}
else {
location = abs((location + q) % n);
}
}
}
int main()
{
cin >> n>> m;
for (int i = 1; i <= n; i++) {
cin >> people[i].direct;
cin >> people[i].profession;
}
for (int i = 0; i < m; i++) {
cin >> p[i] >> q[i];
}
for (int i = 0; i < m; i++) {
caozuo(p[i], q[i]);
}
cout << people[location].profession;
return 0;
}