N=int(input()) bc=0 while N>0: bc+=N&1 N>>=1 if bc==1: print(0) else: print(2**bc-2)