# -*- coding: utf-8 -*-

INF = 1000000

n = int(input())

reached = [False] * (n+1)
ans = INF

def dfs(x,cnt):
    global ans
    if x < 1 or n < x:
        return
    if reached[x] == True:
        return
    if x == n:
        ans = min(ans, cnt)
    reached[x] = True
    go = bit_count(x)
    cnt += 1
    dfs(x + go,cnt)
    dfs(x - go,cnt)

def bit_count(x):
    tmp = str(bin(x))
    one = 0
    for i in tmp:
        if i == "1":
            one += 1
    return one

dfs(1,0)
if ans != INF:
    print(ans+1)
else:
    print(-1)