n = int(input()) w = 1 count = 1 while w != n: steps = list(str(bin(w)))[2:] num = 0 for j in steps: num += int(j) if w + num > n: w -= num else: w += num count += 1 print(count)