from collections import deque from sys import stdin, stdout input = lambda: stdin.readline().rstrip() write = stdout.write def bitCount(i): ret = 0 while i: i &= i - 1 ret += 1 return ret def main(): N = int(input()) que = deque([1]) grid = [i for i in range(N + 1)] move = [None for _ in [0] * (N + 1)] move[1] = 1 cnt = 1 while que: flag = False n = que.popleft() i = bitCount(grid[n]) for j in (n + i, n - i): if 0 < j <= N and move[j] is None: que.append(j) move[j] = cnt + 1 flag = True if flag: cnt += 1 if move[-1] is None: print(-1) else: print(move[-1]) main()