import java.util.ArrayDeque; import java.util.Arrays; import java.util.Deque; import java.util.Scanner; public class Main { static Scanner in = new Scanner(System.in); public static void main(String[] args) { int n = in.nextInt(); if(n == 1){ System.out.println(1); return; } int[] d = new int[n + 1]; Arrays.fill(d, Integer.MAX_VALUE); d[1] = 1; Deque q = new ArrayDeque<>(); q.add(1); while (q.size() > 0) { int a = q.poll(), b = bit(a); if(a + b == n){ System.out.println(d[a] + 1); return; } if (0 < a - b && d[a - b] == Integer.MAX_VALUE) { d[a - b] = d[a] + 1; q.add(a - b); } if (a + b < n && d[a + b] == Integer.MAX_VALUE) { d[a + b] = d[a] + 1; q.add(a + b); } } System.out.println(-1); } public static int bit(int n) { int s = 0; while (n > 0) { if (n % 2 == 1) { s++; } n /= 2; } return s; } }