D = int(input()) res = D for i in range(1,60): start = 0 end = D while end-start>1: mid = (end+start)//2 tmp = 0 for j in range(i+1): tmp += mid//(2**j) if tmp>=D: end = mid else: start = mid tmp = 0 for j in range(i+1): tmp += end//(2**j) if tmp==D: res = min(res,end) print(res)