import sys import os IS_LOCAL = os.environ.get("LOCAL") == "true" def debug(*args, sep=" ", end="\n", flush=False) -> None: if IS_LOCAL: print(*args, sep=sep, end=end, file=sys.stderr, flush=flush) def yn(flg: bool) -> bool: print('Yes' if flg else 'No') return flg def gcd(a, b): a = abs(a); b = abs(b) if a < b: a, b = b, a while b > 0: a, b = b, a % b return a def lcm(a, b): return a * b // gcd(a, b) def main(): readline = sys.stdin.readline N, M = map(int, readline().split()) if N & 1 == 0: ans = N * M else: ans = 0 log = M.bit_length() x = 0 for i in range(log - 1, -1, -1): m = 1 << i if M & m: if x < N: x += 1 ans += (N - 1) * m else: ans += (x - (x & 1)) * m print(ans) if __name__ == "__main__": main()