#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
int n, m;
struct toy {
bool to;
string name;
} t[maxn];
int main() {
freopen("toy.in", "r", stdin);
freopen("toy.out", "w", stdout);
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> t[i].to >> t[i].name;
int now = 1;
for (int i = 1, lr, st; i <= m; i++) {
cin >> lr >> st;
now += (((lr ^ t[now].to) << 1) - 1) * st;
((now += n)) %= n;
if (!now) now = n;
}
cout << t[now].name << endl;
return 0;
}
// 此致我的NOIP2016