N = int(input().strip()) m1 = 0 m2 = 0 while True: if N == 0: break m1 += N m2 = max(m2, m1 + (N * 2) // 2) N = N // 2 print(m2 - m1)