import java.util.*; public class Main { private static Scanner sc = new Scanner(System.in); private static int[] dp; private static int n; public static void main(String[] args) throws Exception { n = sc.nextInt(); dp = new int[n+1]; dfs(1,1); int ret = dp[n]; if (ret==0) { System.out.println(-1); } else { System.out.println(ret); } } private static void dfs(int i, int cnt) { if (dp[i]>0) return; dp[i] = cnt; int c = count(i); if (i-c>0) { dfs(i-c,cnt+1); } if (i+c<=n) { dfs(i+c,cnt+1); } } private static int count(int val) { String s = Integer.toBinaryString(val); int cnt = 0; for (int i = 0;i < s.length();i++) { if (s.charAt(i)=='1') cnt++; } return cnt; } }