import java.util.Scanner; public class Main { private static int N; private static int min = -1; private static boolean flag[] = new boolean[10000]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); dfs(1, 1); System.out.println(min); } private static void dfs(int a, int c){ if(a<1 || a>N){ return; } if(flag[a-1] == true){ return; } if(min != -1 && c>=min){ //flag[a-1] = true; return; } if(a==N){ min = c; } int b = Integer.bitCount(a); dfs(a+b, c+1); dfs(a-b, c+1); } }