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(flag[a-1] == false){ flag[a-1] = true; }else{ return; } if(min != -1 && c>=min){ return; } if(a==N){ min = c; } int bit = Integer.bitCount(a); if(a+bit <= N){ dfs(a+bit, c+1); } if(a-bit > 1){ dfs(a-bit, c+1); } } }