def popcount(n): cnt = 0 while n: cnt += n & 1 n >>= 1 return cnt N = int(input()) print(N + 1 - 2 ** popcount(N))