import java.util.Scanner;
public class Main63 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
while (true) {
int D = scan.nextInt();// 二叉树的深度,从1计
int n = scan.nextInt();// 小猴子数目
int position = 0;// 记录最后停留的位置
if (D == 0 && n == 0)
break;
else {
int count = 1;
for (int i = 0; i < D; i++)
count = 2 * count;
count = count - 1;// 一共的节点数
int[] tree = new int[count];// 用数组存储二叉树
while (n != 0) {
position = 0;
while (2 * position + 2 < tree.length) {
if (tree[position] == 0) {
tree[position] = 1;
position = 2 * position + 1;
} else {
tree[position] = 0;
position = 2 * position + 2;
}
}
n--;
}
System.out.println(position + 1); // 题中的树是从1计数的
}
}
}
}