import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
String[][] career = new String[n][2];
int[][] instr = new int[m][2];
for(int i=0;i<n;i++) {
career[i][0] = sc.next();
career[i][1] = sc.next();
}
for(int i=0;i<m;i++) {
instr[i][0] = sc.nextInt();
instr[i][1] = sc.nextInt();
}
int index=0;
for(int i=0;i<m;i++) {
if(isShun(Integer.parseInt(career[index][0]),instr[i][0])) {
index = (index+instr[i][1])%n;
}else {
index = (index+n-instr[i][1])%n;
}
}
System.out.println(career[(n-index)%n][1]);
}
public static boolean isShun(int a,int b) {
boolean y = ((a^b^1) == 1);
return y;
}
}