N, M = list(map(int, input().split())) ans = 0 cnt = 0 while M != 1: ans += M if M % 2: M += 1 M >>= 1 cnt += 1 if cnt > N : print((1 << N) - 1) else: print(ans + (N - cnt))