package yukicoder; import java.util.*; public class Main { public static void main(String[] args)throws Exception{ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==1){ System.out.println(1); return; } boolean[] arrived=new boolean[n+1]; Arrays.fill(arrived, false); ArrayDeque
que=new ArrayDeque
();
que.add(new P(1,1));
arrived[1]=true;
while(!que.isEmpty()){
P p=que.poll();
int c=count_1(p.n);
int[] a=new int[2];
a[0]=p.n+c;
a[1]=p.n-c;
for(int i=0;i<2;i++){
if(a[i]>n||a[i]<=0)continue;
if(arrived[a[i]]==true)continue;
if(a[i]==n){
System.out.println(p.c+1);
return;
}
que.add(new P(a[i],p.c+1));
arrived[a[i]]=true;
}
}
System.out.println(-1);
}
class P{
int n;
int c;
P(int n,int c){
this.n=n;
this.c=c;
}
}
int count_1(int n){
String str=Integer.toBinaryString(n);
int c=0;
for(int i=0;i