import sys 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 else: return f(x-1,y//2+y%2)+a(x-1,y//2+y%2)*2-y%2 print(f(n,m))