import sys sys.setrecursionlimit(10000) N = int(input()) Q = [1] t = 0 def bin1(n): return bin(n).count("1") def find(x,c): global Q global t d = bin1(x) if t == 0 and x == N: t = c if t == 0 and x-d not in Q and x-d >0: Q.append(x-d) find(x-d,c+1) if t == 0 and x+d not in Q and x+d