import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] min_costs = new int[N + 1]; Arrays.fill(min_costs, Integer.MAX_VALUE); min_costs[1] = 1; Queue queue = new LinkedList(); queue.add(1); while(!queue.isEmpty()){ final int pos = queue.poll(); final int pops = Integer.bitCount(pos); for(int move : new int[]{-pops, pops}){ final int next_pos = pos + move; if(next_pos < 1 || next_pos > N){ continue; }else if(min_costs[next_pos] <= min_costs[pos] + 1){ continue; }else{ min_costs[next_pos] = min_costs[pos] + 1; queue.add(next_pos); } } } System.out.println(min_costs[N] == Integer.MAX_VALUE ? -1 : min_costs[N]); } }