import java.util.Arrays; import java.util.Scanner; public class Main { static int N; static int minCount[]; public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { N = scan.nextInt(); minCount = new int[N+1]; Arrays.fill(minCount, Integer.MAX_VALUE); minCount[1] = 1; solve(1, 1); System.out.println(minCount[N]==Integer.MAX_VALUE? -1:minCount[N]); } } static void solve(int p, int c) { int front = p + Integer.bitCount(p); if(front <= N) { if(c+1 < minCount[front]) { minCount[front] = c+1; solve(front, c+1); } } int back = p - Integer.bitCount(p); if(back >= 1) { if(c+1 < minCount[back]) { minCount[back] = c+1; solve(back, c+1); } } } }