n=int(input()) t=n k=0 while t != 0: k += 1 t = t // 2 if n==1: print(0) else: print(k+pow(2, k)-n)