n = int(input())
c = 0
while n:
    if n & 1:
        c = 2 * c + 1
    n >>= 1
print(c - 1)