import math import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) from collections import deque n = I() if n == 1: print(1) exit() visited = [False] * (n + 1) visited[1] = True q = deque() q.append((1, 1)) while q: x, d = q.popleft() move = bin(x).count('1') for next_pos in (x-move, x+move): if 1 <= next_pos <= n and not visited[next_pos]: if next_pos == n: print(d + 1) exit() visited[next_pos] = True q.append((next_pos, d + 1)) print(-1)