N=int(input()) B=[] while N>0: O=N A=[] while O>0: A.append(O) O//=2 B.append(N*2-sum(A)) N//=2 print(max(B))