from collections import deque N = int(input()) hist = [0 for _ in range(N+1)] que = deque([(1,1)]) hist[1]=1 flag = 0 while que: x,d = que.popleft() if x==N: flag = 1 break n = bin(x)[2:].count("1") if x-n>=1 and hist[x-n]==0: hist[x-n]=1 que.append((x-n,d+1)) if x+n<=N and hist[x+n]==0: hist[x+n]=1 que.append((x+n,d+1)) if flag==0: print(-1) else: print(d)