N=int(input()) a=1 b=1 c=[1] d=[] if N==1: print(1) else: while b!=N: d=c d=list(set(d)) for i in range(0,len(c)): e=bin(c[i]).count("1") p=c[i]+e q=c[i]-e if p<=N: c.append(p) if q>0: c.append(q) a+=1 c=list(set(c)) if N in c: print(a) break if c==d: print(-1) break