import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N=sc.nextInt(); int ans=1; int[] check=new int[N+1]; Queue queue = new LinkedList<>(); queue.offer(1); check[1]=1; while(!queue.isEmpty()){ int temp1 = queue.poll(); int temp2 = temp1+Integer.bitCount(temp1); int temp3=temp1-Integer.bitCount(temp1); if(temp2<=N&&check[temp2]==0){ queue.offer(temp2); check[temp2]=check[temp1]+1; } if(temp3>=1&&check[temp3]==0){ queue.offer(temp3); check[temp3]=check[temp1]+1; } } if(check[N]==0){ System.out.println(-1); }else{ System.out.println(check[N]); } } }