from collections import deque import copy import math N = int(input()) if N == 1: print(0) else: ans, already, que = 1, set(), deque([1]) while len(que) > 0: nque = deque() while len(que) > 0: n = que.popleft() already.add(n) step = sum([(n >> i) % 2 for i in range((int(math.log2(n)) + 1))]) if n - step >= 1 and n - step not in already: nque.append(n - step) if n + step < N and n + step not in already: nque.append(n + step) elif n + step == N: print(ans + 1) exit() que = copy.copy(nque) ans += 1 print(-1)