n = int(input()) c = v = 0 while n: v = max(c+(n<<1),v) c += n n >>= 1 print(v-c)