import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Integer n = sc.nextInt(); Integer depth = 0; Deque dq = new ArrayDeque<>(); boolean solved = false; boolean seen[] = new boolean[n + 1]; seen[1] = true; for (int i = 2; i <= n; i++) { seen[i] = false; } dq.addFirst(1); while (!dq.isEmpty()) { Integer adj = dq.getFirst(); boolean found = false; dq.removeFirst(); depth++; if (adj == n) { System.out.println(depth); solved = true; break; } Integer cnt = countBit(adj); if (adj - cnt >= 1 && !seen[adj - cnt]) { dq.addLast(adj - cnt); seen[adj - cnt] = true; found = true; } if (adj + cnt <= n && !seen[adj + cnt]) { dq.addLast(adj + cnt); seen[adj + cnt] = true; found = true; } if (!found) { depth--; } } if (!solved) { System.out.println(-1); } sc.close(); } static Integer countBit(Integer n) { Integer cnt = 0; while (n != 0) { cnt += n % 2; n /= 2; } return cnt; } }