from collections import deque
n=int(input())
L=[10**9]*(n+1)
L[1]=1
q=deque([(1,1)])
while q:
    x,t=q.popleft()
    k=bin(x).count("1")
    for dk in [k,-k]:
      if 0<x+dk<=n and t+1<L[x+dk]:
        L[x+dk]=t+1
        q.append((x+dk,t+1))

print(L[n] if L[n]!=10**9 else -1)