import java.util.ArrayDeque; import java.util.Queue; import java.util.Scanner; public class Main_yukicoder3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] dp = new int[n]; Queue st = new ArrayDeque(); dp[0] = 1; st.add(1); while(!st.isEmpty()) { int now = st.remove(); if (now == n) { break; } int d = Integer.bitCount(now); if (now + d <= n && dp[now + d - 1] == 0) { dp[now + d - 1] = dp[now - 1] + 1; st.add(now + d); } if (now - d >= 1 && dp[now - d - 1] == 0) { dp[now - d - 1] = dp[now - 1] + 1; st.add(now - d); } } if (dp[n - 1] != 0) { System.out.println(dp[n - 1]); } else { System.out.println(-1); } sc.close(); } }