N = int(input())

que = [1]
now = 1
visited = [False for i in range(N+1)]
haba = [-1 for i in range(N+1)]
visited[1] = True
haba[1] = 1
haba_count = 1

while len(que) > 0 and now != N:
    now = que.pop(0)
    haba_count = haba[now] + 1
    step_width = bin(now).count("1")
    next_f = now + step_width
    next_b = now - step_width
    if next_f <= N and visited[next_f] is False:
        que.append(next_f)
        visited[next_f] = True
        haba[next_f] = haba_count
    if next_b >= 1 and visited[next_b] is False:
        que.append(next_b)
        visited[next_b] = True
        haba[next_b] = haba_count

# print(haba)
        
        
if now == N:
    print(haba[N])
else:
    print(-1)