package yukicoder; 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(); //long start = System.currentTimeMillis(); //無理か判断 int m = 1; int distance = 0; int target; int muripo = 0; int count = 1; while (m != N) { count++; distance = 0; //System.out.println("----count:" + count); 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 (m == muripo) { System.out.println(-1); //long end = System.currentTimeMillis(); //System.out.println((end - start) + "ms"); return; } if (0 == muripo) { muripo = m; } } else { target = m + distance; } //System.out.println("target:" + target); //move m = target; //System.out.println("m:" + m); } //long end = System.currentTimeMillis(); //System.out.println((end - start) + "ms"); System.out.println(count); } }