import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Queue; public class No3 { public static void main(String[] args) throws IOException{ //ビットすごろく int N = Integer.parseInt(readStr()[0]) , k = 0; int[] root = new int[N + 1]; root[1] = 1; Queue qu = new ArrayDeque<>(); qu.add(1); while(qu.size() > 0 && (k = qu.poll()) < N) { if(k + Integer.bitCount(k) <= N) { root[k + Integer.bitCount(k)] = root[k] + 1; qu.add(k + Integer.bitCount(k)); } if(k - Integer.bitCount(k) >= 1 && root[k - Integer.bitCount(k)] == 0) { root[k - Integer.bitCount(k)] = root[k] + 1; qu.add(k - Integer.bitCount(k)); } } System.out.println(root[N] == 0 ? -1 : root[N]); } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }