import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; import java.util.Scanner; public class No3 { public static void main(String[]args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean [] boo = new boolean[n]; int []m = new int[n]; Arrays.fill(m, Integer.MAX_VALUE); for(int i=0;i q = new ArrayDeque(); boo[0]=true; q.add(1); m[0]=1; while(!q.isEmpty()) { int now = q.poll(); int bitcnt = Integer.bitCount(now); int b = now-bitcnt; int f = now+bitcnt; if(b>0) { m[b-1]=Math.min(m[b-1],m[now-1]+1); if(!boo[b-1]) { q.add(b); } boo[b-1]=true; } if(f<=n) { m[f-1]=Math.min(m[f-1],m[now-1]+1); if(!boo[f-1]) { q.add(f); } boo[f-1]=true; } } if(m[n-1]==Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(m[n-1]); } sc.close(); } }