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) 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: loc = bounce else: loc -= rng cond = [] for i in range(2,goal//2+1,2): if ops >= i: h = i // 2 cond.append(loc == his[-h] == his[-i]) stuck = any(cond) if stuck: return -1 return ops print(bitJusawi(inp))