import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int m = 1; int distance = 0; int target; Map muripo = new HashMap<>(); int count = 1; while (m != N) { count++; distance = 0; char[] c = Integer.toBinaryString(m).toCharArray(); for (int i = 0;i < c.length;i++) { if (c[i] == '1') { distance++; } } //get target if (N < m + distance) { target = m - distance; // 以前同じmで戻っている if (muripo.containsKey(m)) { System.out.println(-1); return; } muripo.put(m, m); } else { target = m + distance; } //move m = target; } System.out.println(count); } }