N = int(input()) mn = 0 x = N while x: mn += x x //= 2 mx = N*2 print(mx-mn)