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]) , d = 0 , pl , mi; int[] root = new int[N + 1]; root[1] = 1; Queue qu = new ArrayDeque<>(); qu.add(1); while(qu.size() > 0) { d = qu.poll(); pl = d + Integer.bitCount(d); mi = d - Integer.bitCount(d); if(pl <= N && (root[pl] == 0 || root[pl] > root[d] + 1)) { root[pl] = root[d] + 1; if(pl < N) { qu.add(pl); } } if(mi >= 1 && (root[mi] == 0 || root[mi] > root[d] + 1)) { root[mi] = root[d] + 1; qu.add(mi); } } 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; } }