# coding: utf-8 # Your code here! n=int(input()) lst = [0]*(n+1) def f(num,cnt): if num==n: print(cnt) return True if num<1 or num > n: return False step = str(bin(num))[2:].count("1") fowd_n = num+step back_n = num-step if fowd_n<=n and lst[fowd_n]==0: lst[fowd_n]=1 if f(fowd_n,cnt+1): return True else: lst[fowd_n]=0 if back_n<=n and lst[back_n]==0: lst[back_n]=1 if f(back_n,cnt+1): return True else: lst[back_n]=0 return False lst[1]=1 if f(1,1)==False: print(-1)