import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class BitSugoroku { public static void main(String[] args) { BitSugoroku p = new BitSugoroku(); } public BitSugoroku() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); solve(n); } public void solve(int n) { int[] isVisit = new int[n+1]; Arrays.fill(isVisit, -1); PriorityQueue

queue = new PriorityQueue

(); queue.offer(new P(1, 1)); while(!queue.isEmpty()){ P p = queue.poll(); if(isVisit[p.x] < 0) isVisit[p.x] = p.d; else continue; int move = Integer.bitCount(p.x); if(p.x+move <= n && isVisit[p.x+move] < 0){ queue.offer(new P(p.x+move, p.d+1)); } if(p.x-move >= 1 && isVisit[p.x-move] < 0){ queue.offer(new P(p.x-move, p.d+1)); } } System.out.println(isVisit[n]); } public class P implements Comparable

{ public int x; public int d; public P(int x, int d) { this.x = x; this.d = d; } @Override public int compareTo(P o) { return this.d - o.d; } } }