import java.util.ArrayDeque; import java.util.Deque; import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); sub s = new sub(); int goal = sc.nextInt(); int num = -1; int[] vect = new int [goal]; for(int i = 0 ; i < vect.length ; i++)vect[i] = -1;//初期化 Deque qu = new ArrayDeque (); qu.add(1); vect[0] = 0; while(vect[goal - 1] == -1) { try { num = qu.getFirst();// キューから先頭頂点を取り出す qu.removeFirst(); }catch (Exception e) {//キューの中身がなくなったら System.out.println(-1); return; } int count = s.counter(num); // num から辿れる頂点をすべて調べる if(num +count <= goal) {//正の方向 if(vect[num + count - 1] == -1) { vect[num + count - 1] = vect[num - 1] + 1; qu.add(num + count); } } if(num - count > 0) {//負の方向 if(vect[num - count - 1] == -1) { vect[num - count - 1] = vect[num - 1] + 1; qu.add(num - count); } } } System.out.println(vect[goal - 1] + 1); } } class sub{ int counter(int num) { int count = 0; for(int i = num ; i > 0 ; i = i / 2) { if(i % 2 == 1) count++; } return count; } }