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(); 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 (0 < a - b && d[a - b] > d[a] + 1) { d[a - b] = d[a] + 1; q.add(a - b); } if (a + b <= n && d[a + b] > d[a] + 1) { d[a + b] = d[a] + 1; q.add(a + b); } } System.out.println(d[n] == Integer.MAX_VALUE ? -1 : d[n]); } public static int bit(int n) { int s = 0; while (n > 0) { if (n % 2 == 1) { s++; } n /= 2; } return s; } }