import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] dp = new int[n + 1]; ArrayDeque deq = new ArrayDeque<>(); deq.add(new Path(1, 1)); Arrays.fill(dp, Integer.MAX_VALUE); while (deq.size() > 0) { Path p = deq.poll(); if (dp[p.idx] <= p.value) { continue; } dp[p.idx] = p.value; int pop = getPop(p.idx); if (p.idx + pop <= n) { deq.add(new Path(p.idx + pop, p.value + 1)); } if (p.idx - pop >= 1) { deq.add(new Path(p.idx - pop, p.value + 1)); } } System.out.println(dp[n] == Integer.MAX_VALUE ? -1 : dp[n]); } static class Path { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } } static int getPop(int x) { int pop = 0; while (x > 0) { pop += x % 2; x >>= 1; } return pop; } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }