from fractions import Fraction def read_int(): return int(input()) def read_ints(): return list(map(int, input().split())) D = read_int() def f(x): y = 0 while x != 0: y += x if y == D: return True x //= 2 return False answer = 10 ** 100 for i in range(1, 100): # x(1 + 1/2 + 1/4 + 1/8 + ...) ~= D x = Fraction(D) / ((1 - Fraction(1, 2) ** i) / (1 - Fraction(1, 2))) x = int(x) for d in range(-10, 10): if x + d >= 1 and f(x + d): answer = min(answer, x + d) print(answer)