N = int(input()) root = [-1] * (N + 1) bitmap = [0] for i in range(1, N+1): tmp = bin(i) bitmap.append(tmp.count('1')) pos = 1 count = 1 root[pos] = 1 while True: if pos + bitmap[pos] > N: pos = pos - bitmap[pos] if root[pos] == 1: count = -1 break else: root[pos] = 1 count += 1 elif pos + bitmap[pos] < N: pos = pos + bitmap[pos] if root[pos] == 1: count = -1 break else: root[pos] = 1 count += 1 else: count += 1 break print(count)