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