N = int(input()) P = [] while N: P.append(N) N >>= 1 ans = 0 tmp = 0 for p in P: ans = max(ans, tmp + 2 * p) tmp += p print(ans - sum(P))