def check(x,D): res=0 while(x): res+=x x//=2 if res==D: return True if res==D: return True else: return False D=int(input()) ans=D for x in range(D//2,D//2+100000): if check(x,D): ans=min(ans,x) print(ans)