N, M = map(int, input().split()) x = pow(2, N - 1) if x <= M: print(x * 2 - 1) exit() cnt = 0 ans = M while M > 1: M = -(-M//2) ans += M cnt += 1 ans += N - cnt - 1 print(ans)