n, m = map(int,input().split()) if m == 1: print(n) exit() maxi = 0 for v in range(m + 1000): if 2 ** (v + 1) >= m: maxi = v + 1 break if maxi >= n: ans = 2 ** n - 1 print(ans) exit() now = 2 ** maxi - m if now != 0: s = bin(now)[2:] ans = [2] for i in range(len(s)): if s[i] == '1': ans.append(2 * ans[-1] - 1) else: ans.append(2 * ans[-1]) l = n - len(s) print(sum(ans) + l - 1) else: ans1 = 2 ** (maxi + 1) - 1 ans2 = n - maxi - 1 print(ans1 + ans2)