N, M = map(int, input().split()) if M == 1: print(N) else: t = (M - 1).bit_length() s = bin(M - 1).count('1') sum_first = 2 * (M - 1) - s + t sum_second = max(0, N - t) print(sum_first + sum_second)