import java.util.ArrayDeque; import java.util.Scanner; public class Bitsugoroku { public static void main(String[] args) { Scanner s =new Scanner(System.in); int N = s.nextInt(); s.close(); int[] way = new int[N+1]; way[1] = 1; ArrayDeque queue = new ArrayDeque<>(); queue.offer(1); while(queue.size() != 0){ int p = queue.poll(); if(p == N){ break; } int b = Integer.bitCount(p); if(p+b <= N){ if(way[p+b] == 0||way[p+b] > way[p]+1){ queue.offer(p+b); way[p+b] = way[p] + 1; } } if(p-b > 0&&( way[p-b] == 0 || way[p-b] > way[p] + 1)){ queue.offer(p-b); way[p-b] = way[p] + 1; } } if(way[N] == 0){ System.out.println("-1"); }else{ System.out.println(way[N]); } } }