#include<iostream>
using namespace std;
struct mem
{
int tow;
string mem;
};
struct point
{
int fx;
int cishu;
};
int main()
{
int n, z;
cin >> n >> z;
mem stu[200000];
for (int i = n; i>=1; i--)
{
cin >> stu[i].tow >> stu[i].mem;
}
point po[200000];
for (int i = 1; i <= z; i++)
{
cin >> po[i].fx >> po[i].cishu;
}
int lo=n;
for (int i = 1; i <= z; i++)
{
if (po[i].fx == 0&&stu[lo].tow==1|| po[i].fx == 1 && stu[lo].tow == 0)
{
while (po[i].cishu >= 1)
{
if (lo == 1)
{
lo = n; po[i].cishu--;
}
else
{
lo--;
po[i].cishu--;
}
}
}
if (po[i].fx == 0 && stu[lo].tow == 0|| po[i].fx == 1 && stu[lo].tow == 1)
{
while (po[i].cishu >= 1)
{
if (lo == n)
{
lo = 1; po[i].cishu--;
}
else
{
lo++;
po[i].cishu--;
}
}
}
}
cout << stu[lo].mem;
return 0;
}