#include <bits/stdc++.h>
using namespace std;
class person
{
public:
int dc;
string s;
} a[10000007];
int n, m;
inline void solve(void)
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i].dc >> a[i].s;
}
int id = 1;
for (int i = 1; i <= m; i++)
{
int ai, si;
cin >> ai >> si;
if (ai == 0)
{
if (a[id].dc)
{
id = (id + si) % n;
}
else
{
id = (id - si + n) % n;
}
}
else
{
if (a[id].dc)
{
id = (id - si + n) % n;
}
else
{
id = (id + si) % n;
}
}
}
cout << a[id].s;
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}