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= n){
if (first < 0){
first += n ;
}else {
first -= n;
}
}
}
System.out.println(p[first].name);
}
public static class peo {
int direction;
String name;
peo(int direction, String name) {
this.direction = direction;
this.name = name;
}
}
}