from collections import deque def bitcount(n): return bin(n).count("1") def main(): n=int(input()) dq=deque() dq.append((1,1)) seen=set() while len(dq)>0: x,y=dq.popleft() if x==n: print(y) return if x in seen: continue seen.add(x) if x+bitcount(x)<=n: dq.append((x+bitcount(x),y+1)) if x-bitcount(x)>0: dq.append((x-bitcount(x),y+1)) print(-1) if __name__=="__main__": main()