n = int(input()) l = [1 << i for i in range(60) if 1 << i & n] ans = [] for b in range(1, 1 << len(l)): cnt = 0 for i in range(len(l)): if 1 << i & b: cnt += l[i] ans.append(cnt) print(sorted(ans)[(len(ans) + 1) // 2 - 1])