import java.io.Console; import java.util.*; public class No3 { public static void main(String[] args){ Scanner sc =new Scanner(System.in); int N = sc.nextInt(); int list[] = new int[N + 15]; List q1 = new ArrayList(); List q2 = new ArrayList(); q1.add(1); int count = 0; int i = 0; while(i<1){ q1.addAll(q2); q2.clear(); for(int Num : q1){ int one = Integer.bitCount(Num); if(Num-one>0){ if(list[Num-one]==0){ count=count+1; list[Num-one]=count; q2.add(Num-one); } } if(Num+one<=N){ if(list[Num+one]==0){ count=count+1; list[Num+one]=count; q2.add(Num+one); } } } if(list[N]!=0){ System.out.println(list[N]); i = i+1; break; }else if(q2.isEmpty()){ System.out.println(-1); i = i+1; break; } } } }