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 now = 2 ** maxi - m 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)