D = int(input()) def f(x): result = 0 while x != 0: result += x x //= 2 if result >= D: break 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(10, -1, -1): if t < 0: continue if f(t - j) == D: print(t - j) exit()