import java.util.ArrayDeque; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] min = new int[N+1]; min[1] = 1; Queue q = new ArrayDeque<>(); q.add(1); while (!q.isEmpty()) { int x = q.poll(); if (x == N) { break; } int v1 = x + count1(x); int v2 = x - count1(x); if (v1 > 0 && v1 <= N && min[v1] == 0) { q.add(v1); min[v1] = min[x] + 1; } if (v2 > 0 && v2 <= N && min[v2] == 0) { q.add(v2); min[v2] = min[x] + 1; } } if (min[N] == 0) { System.out.println(-1); } else { System.out.println(min[N]); } sc.close(); } static int count1(int x) { int tmp = x; int cnt = 0; while (tmp != 0) { cnt += tmp & 1; tmp >>= 1; } return cnt; } }