N = int(input()) log = [] while N != 0: log.append(N) N //= 2 normal = sum(log) total = 0 ans = 0 for score in log: ans = max(ans, score * 2 + total - normal) total += score print(ans)