var m,n,i,j,k,l:longint;
s:char;
a,b,c:array[0..101000] of longint;
st:array[0..101000] of string;
begin
assign(input,'toya.in');
assign(output,'toya.out');
reset(input);
rewrite(output);
readln(m,n);
for i:=1 to m do
readln(a[i],s,st[i]);
for i:=1 to n do
readln(b[i],c[i]);
l:=1;
k:=0;
for i:=1 to n do
begin
if a[l]=0 then if b[i]=0 then l:=l-c[i]
else l:=l+c[i]
else if b[i]=0 then l:=l+c[i]
else l:=l-c[i];
if l>m then l:=l-m;
if l<1 then l:=l+m;
end;
writeln(st[l]);
close(input);
close(output);
end.