import java.util.LinkedList; import java.util.Scanner; public class BitSugoroku { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); // 1 <= N <= 10000 int[] distance = new int[10001]; //[0] ~ [10000] LinkedList queue = new LinkedList<>(); queue.add(1); distance[1] = 1; for(int i=2;i<=n;i++){ distance[i] = -1; } int bitCount; int num; int plus; int minus; while(!queue.isEmpty()){ num = queue.poll(); bitCount = Integer.bitCount(num); plus = num + bitCount; minus = num - bitCount; if(minus >= 1){ if(distance[minus] == -1){ distance[minus] = distance[num] + 1; queue.add(minus); } } if(plus <= n){ if(distance[plus] == -1){ distance[plus] = distance[num] + 1; queue.add(plus); } } } System.out.println(distance[n]); } }