D = int(input()) def judge(l,cnt): m = l dis = l for i in range(cnt): dis += m//2 m //= 2 return dis res = D for i in range(1,61): ok, ng = 10**18+1,0 while ok-ng>1: mid = (ok+ng)//2 dis = judge(mid,i) if dis>=D: ok = mid else: ng = mid if judge(ok,i)==D: res = min(res,ok) print(res)