import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Queue; import java.util.StringTokenizer; public class Main { static ArrayList> graph_list = new ArrayList>(); public static void main(String[] args) { FastReader fr = new FastReader(); int n = fr.nextInt(); for(int i=0;i<=n;i++) { graph_list.add(new ArrayList()); } for(int i=1;i<=n;i++) { int bit = popcount(i); if(i-bit>=1) graph_list.get(i).add(i-bit); if(i+bit<=n) graph_list.get(i).add(i+bit); } int dist = bfs_dist(n,1,n); if(dist==Integer.MAX_VALUE) { dist=-1; }else { dist++; } System.out.println(dist); } static int bfs_dist(int n, int root, int goal) { Queue todo = new ArrayDeque(); int[] dist = new int[n+1]; Arrays.fill(dist, Integer.MAX_VALUE); dist[root] = 0; todo.add(root); while(!todo.isEmpty()) { Integer node = todo.poll(); for(Integer i:graph_list.get(node)) { if(dist[i]>dist[node]+1) { todo.add(i); dist[i]=dist[node]+1; } } } return dist[goal]; } static int popcount(int x) { x = (x & 0x55555555) + (x >> 1 & 0x55555555); x = (x & 0x33333333) + (x >> 2 & 0x33333333); x = (x & 0x0f0f0f0f) + (x >> 4 & 0x0f0f0f0f); x = (x & 0x00ff00ff) + (x >> 8 & 0x00ff00ff); return (x & 0x0000ffff) + (x >>16 & 0x0000ffff); } } class FastReader { private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000); private StringTokenizer tokenizer; String next() { try{ while(tokenizer==null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } }catch(IOException e){ e.printStackTrace(); } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } char[] nextCharArray() { return next().toCharArray(); } char nextSingleChar() { //一文字じゃなかったら' '(空白文字)返す char[] c = next().toCharArray(); if(c.length==1) { return c[0]; }else { return ' '; } } String[] nextStringArray(int n) { String[] s = new String[n]; for (int i = 0; i < n; i++) { s[i] = next(); } return s; } }