N = int(input()) checked = list(-1 for i in range(N + 1)) checked[0] = 0 move = list(map(bin, range(N))) move = list(move[i].count('1') for i in range(N)) node = [0] count = 1 pos = 1 def play(): global count global pos checked[pos] = count def moving(): global count global pos if pos + move[pos] <= N and checked[pos + move[pos]] == -1: pos += move[pos] count += 1 else: pos = node.pop() count = checked[pos] if checked[pos - move[pos]] == -1: checked[pos - move[pos]] = count + 1 node.append(pos - move[pos]) moving() else: moving() for i in range(N): if pos == N: print(count) break elif node == []: print(-1) break else: play()