D = int(input()) def f(x): result = 0 while x != 0 and result < D: result += x x //= 2 return result for i in range(60, 0, -1): t = D * (2 ** (i - 1)) // (2 ** i - 1) if f(t) == D: for j in range(-2, 1): if f(t + j) == D: print(t) exit()