import java.util.Scanner;
public class P1563玩具谜题 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
peo[] p = new peo[n];
for (int i = 0; i < n; i++) {
//小人朝向,0:朝内,1:朝外 0 0 -,0 1 +,1 0 +, 1 1 -
p[i] = new peo(sc.nextInt(), sc.next());
}
//第一个小人的下标
int first = 0;
//输入指令,0:左移,1:右移。本题以逆时针为顺序,因此逆时针+,顺时针-
for (int i = 0;i<m;i++){
//指令要移动的方向
int dre = sc.nextInt();
int ge = sc.nextInt();
if (p[first].direction == 0 && dre == 0){
first -= ge;
}else if (p[first].direction == 0 && dre == 1){