from collections import deque def bit(x): x = bin(x) x = x.count('1') return x def bit_fb(x): a = x - bit(x) b = x + bit(x) return a,b N = int(input()) A = [0] * (N+1) A[1] = 1 B = deque() B.append(1) while B: C = B.popleft() if C == N: print(A[C]) break D,E = bit_fb(C) if 0 < D <= N and A[D] == 0: B.append(D) A[D] = A[C] + 1 if 0 < E <= N and A[E] == 0: B.append(E) A[E] = A[C] + 1 if A[N] == 0: print(-1)