d = int(input()) ans = 1 << 70 for c in range(70): x = (1 << (c + 1)) - 1 y = d while x < y: x <<= 1 l = 0 while x > 0: if y >= x: y -= x l += 1 << (x.bit_length() - 1) x >>= 1 if y == 0: ans = min(ans, l) print(ans)