#!usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def main(): def popcount(n): return bin(n).count("1") n = I() d = [float("inf")]*(n+1) d[1] = 1 q = deque([1]) while q: x = q.popleft() dx = popcount(x) nd = d[x]+1 for nx in (x-dx,x+dx): if 1 <= nx <= n and nd < d[nx]: d[nx] = nd q.append(nx) ans = d[n] if ans == float("inf"): ans = -1 print(ans) return if __name__ == "__main__": main()