def f(n, m): if n == 1: return m if n % 2 == 0: return n + f(n//2, m - 1) else: return n + f((n + 1)//2, m - 1) N, M = map(int, input().split()) ans = 2 ** N - 1 print(min(ans, f(M, N)))