inp = int(input()) def bitJusawi(goal): move = lambda x: list(map(int, list(bin(x)[2:]))).count(1) his = [] ; loc = 0; ops = 0; rem = goal - loc while goal != loc: his.append(loc) if len(his) >= 11: his.pop(0) rem = goal - loc if ops == 0: ops = 1; loc = 1 else: ops += 1 rng = move(loc) if rem >= rng: loc += rng else: bounce = goal - ((loc + rng) - goal) if loc - rng < bounce and loc != bounce: loc = bounce else: loc -= rng cond = [] for i in range(2,11,2): if ops >= i: h = i // 2 cond.append(loc == his[-h] == his[-i]) if any(cond): return -1 return ops print(bitJusawi(inp))