n = int(input()) sc = 0 ans = 0 while n > 0 : # print(n) sc += n ans = max(sc + n,ans) n = n//2 print(ans-sc)