#include<iostream>#include<cstdio>#define SIZE (int)1e5 + 10usingnamespace std;struct Node{int direction;char name[20];} a[SIZE];intmain(){freopen("cpp.in","r",stdin);freopen("cpp.out","w",stdout);int n, m, w =0;scanf("%d%d",&n,&m);for(int i =0; i < n;++i){scanf("%d%s",&a[i].direction,&a[i].name);}for(int i =1; i <= m;++i){int x, y;scanf("%d%d",&x,&y);if(a[w].direction == x){
y *=-1;}
w =(w + y + n)% n;}printf("%s\n", a[w].name);return0;}