N = int(input()) def nbit(n): b = 0 while 0 < n: b += n & 1 n >>= 1 return b count = 1 current = 1 done = {} while current != N: bit = nbit(current) next = current + bit count += 1 if next == N: break elif next < N and next not in done: done[next] = 1 current = next elif N < next and next not in done: done[next] = 1 current = current - bit else: count = -1 break print(count)