from math import log2 d = int(input()) ans = d for cnt in range(int(log2(d)) + 2): left, right = 0, d while right - left > 1: mid = (left + right) // 2 dd = mid res = dd for _ in range(cnt): dd //= 2 res += dd if res >= d: right = mid else: left = mid dd = right res = dd for _ in range(cnt): dd //= 2 res += dd if res == d: ans = min(ans, right) print(ans)