n=int(input()) lst = [0]*(n+1) def f(num,cnt): if num==n: print(len(cnt)) 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)