from collections import deque

N = int(input())

def one_counter(num):
    return sum([ int(i) for i in bin(num)[2:] ])

line = [ one_counter(i) for i in range(1,N+1) ]
reach = [ -1 for i in range(N) ]

q = deque([0])
end = N - 1
reach[0] = 1

while q:
    pos = q.popleft()
    
    if pos == end:
        print(reach[-1])
        exit()
    
    next_move = [ line[pos], -line[pos] ]
    
    for m in next_move:
        next_pos = pos + m
        
        if not 0 <= next_pos <= end:
            continue
        
        if reach[next_pos] == -1:
            q.append(next_pos)
            reach[next_pos] = reach[pos] + 1
print(-1)