nin = int(input()) visit = [] mark = 100000 def dps(n,m=1): if n == nin: visit.append(n) global mark mark = min(m,mark) return bit = 0 visit.append(n) for item in list(str(bin(n))): if item == "1": bit += 1 for item in [n+bit,n-bit]: if item < 1 or item > nin: continue else: if not item in visit: dps(item,m+1) dps(1) if nin in visit: print(mark) else: print(-1)