import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int[] visited = new int[N + 1]; Arrays.fill(visited, 0); visited[1] = 1; Queue q = new ArrayDeque<>(); q.add(1); while (!q.isEmpty()) { int u = q.poll(); if (u == N) { System.out.println(visited[u]); return; } int move = Integer.bitCount(u); int v1 = u + move; if (v1 <= N && visited[v1] == 0) { q.add(v1); visited[v1] = visited[u] + 1; } int v2 = u - move; if (v2 > 0 && visited[v2] == 0) { q.add(v2); visited[v2] = visited[u] + 1; } } System.out.println(-1); } }