import copy N = int(input()) endcount = [] def dfs(num, count, passlist): count += 1 #print (str(count) + ':' + str(num)) progress = getBynum(num) if num + progress == N: endcount.append(count+1) return elif (num + progress < N) & ((num + progress) not in passlist): #print(passlist) passlist.append( num + progress) dfs(num + progress, count, copy.deepcopy(passlist)) if num - progress == N: endcount.append(count+1) return elif (num - progress > 1) & ((num - progress) not in passlist): passlist.append( num - progress) dfs(num - progress, count, copy.deepcopy(passlist)) def getBynum(num): return bin(num)[2:].count('1') dfs(1 ,0, [1]) if(len(endcount) == 0): print(-1) else: print(min(endcount))