n=int(input()) ps=[1] cnt=1 log=set([1]) while n not in ps: nps=[] for p in ps: dp=format(p,"b").count("1") np=p+dp if 0 < np < n + 1 and np not in log: nps+=[np] log.add(np) np=p-dp if 0 < np < n + 1 and np not in log: nps+=[np] log.add(np) if len(nps)==0: cnt=-1 break cnt+=1 ps=nps print(cnt)