import sys import math sys.setrecursionlimit(67108864) n,m=list (map(int,input ().split())) def f(x,y): def a(x,y): return min(2**(x-1),y,) if x==1: return 1 elif y==1: return x elif 2**(x-1)<=y: return 2**x-1 elif y%2==0: yy=int(y/2) return f(x-1,yy)+a(x-1,yy)*2 else: yy=math.ceil(y/2) return f(x-1,yy)+a(x-1,yy)*2-1 print(f(n,m))