n,a=int(input()),0 while n>0: x,b=n,0 while x>0:b+=x;x//=2 a=max(a,n*2-b);n//=2 print(a)