import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); scan.close(); boolean flag[] = new boolean[N+1]; int ans = Integer.MAX_VALUE; Queue q = new LinkedList<>(); q.add(new Node(1,1)); while(!q.isEmpty()) { Node v = q.poll(); if(v.number == N) { ans = Math.min(ans, v.number); continue; } flag[v.number] = true; int nextRight = v.number + (Integer.bitCount(v.number)); if(nextRight <= N && !flag[nextRight]) { q.add(new Node(nextRight, v.steps+1)); } int nextLeft = v.number - (Integer.bitCount(v.number)); if(nextLeft >= 1 && !flag[nextLeft]) { q.add(new Node(nextLeft, v.steps+1)); } } if(ans == Integer.MAX_VALUE) { System.out.println("-1"); } else { System.out.println(ans); } } } class Node { int number; int steps; Node(int number , int steps) { this.number = number; this.steps = steps; } }