def NX(a): global N,K K.append(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=[[1,1]] if N!=1 else [] K=[] while len(buf): c,n=buf.pop(0) for i in NX(n): if i==N: buf.clear() G=c+1 buf.append([c+1,i]) print(G)