package yukicoder; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { BufferedReader buff = new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(buff.readLine()); int ans = 1; // 移動数 boolean[] check = new boolean[N]; int i = 1; while (i < N) { String str = Integer.toBinaryString(i); int count = 0; for (int j = 0; j < str.length(); ++j) { if (str.charAt(j) == '1') { count++; } } if (count + i == N) { ans++; break; } else if (count + i < N) { ans++; i += count; check[i] = true; } else if(count + i > N){ if(check[i - count] || i - count <= 0){ ans = -1; break; } else { ans++; i -= count; check[i] = true; } } } System.out.println(ans); } catch (Exception e) { e.getStackTrace(); } } }