D = int(input()) def ok(x): if x == D: return True now = x while x: x >>= 1 now += x if now == D: return True return False ans = D for n in range(2, 61): m = pow(2, n-1)*D // (pow(2, n) - 1) for i in range(60): x = m + i if ok(x): ans = min(ans, x) print(ans)