from collections import deque def NX(a): global N,K K.add(a) r=[] b=bin(a).count("1") if 0 < a-b and not a-b in K:r.append(a-b) if N >= a+b and not a+b in K:r.append(a+b) return(r) N=int(input()) G=-1 if N!=1 else 1 buf=deque() buf.append([1,1]) if N==1: buf.clear() K=set([]) while len(buf): c,n=buf.popleft() if n in K:continue for i in NX(n): if i==N: buf.clear() G=c+1 buf.append([c+1,i]) print(G)