from collections import deque
N=int(input())

a=deque([0]*(N + 1))
a[1]=1
b=deque()
b.append(1)

while(len(b)!=0):
    x=b.popleft()
    if(x==N):
        print(a[x])
        break
    step=format(x,'b').count("1")
    y1=x+step
    y2=x-step
    if(0<y1<=N and a[y1]==0):
        b.append(y1)
        a[y1]=a[x]+1
    if(0<y2<=N and a[y2]==0):
        b.append(y2)
        a[y2]=a[x]+1
else:
    print(-1)