N = int(input()) f = lambda x : sum(1 for y in str(bin(x)) if y == '1') ans = 100001 q = [1] c = 1 r = [] while c < ans and len(q) > 0: a = [] for i in q: if i == N: ans = c elif (not i in r): r += [i] n, m = i+f(i), i-f(i) if n <= N : a += [n] if m > 0 : a += [m] q = a c += 1 print(ans if ans<100001 else -1)