#include
typedef struct wanjuren {
int head;
char s1[15];
}Node;
Node s[100000] = { 0 };
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d %s", &s[i].head, s[i].s1);
}
int now = 0, x, y;
for (int i = 1; i <= m; i++) {
scanf("%d %d", &x, &y);
if (s[now].head == 0 && x == 0) {
now = (now + n - y) % n;
continue;
}
if (s[now].head == 0 && x == 1) {
now = (now + y) % n;
continue;
}
if (s[now].head == 1 && x == 0)
{
now = (now + y) % n;
continue;
}
if (s[now].head == 1 && x == 1) {
now = (now + n - y) % n;
continue;
}
}
printf("%s", s[now].s1);
return 0;
}