import java.util.LinkedList; 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(); int hosuu[] = new int[N+1]; hosuu[1] = 1; Queue queue = new LinkedList(); queue.offer(1); while(true) { Integer i = queue.poll(); if(i == null) { break; } if(i - bitcount(i) > 0 && hosuu[i - bitcount(i)] == 0){ hosuu[i - bitcount(i)] = hosuu[i] + 1; queue.offer(i - bitcount(i)); } if(i + bitcount(i) <= N && hosuu[i + bitcount(i)] == 0) { hosuu[i + bitcount(i)] = hosuu[i] + 1; queue.offer(i + bitcount(i)); } } if(hosuu[N] == 0) { System.out.println(-1); }else { System.out.println(hosuu[N]); } } public static int bitcount(int x) { int bit = 0; while(x != 0) { bit += x % 2; x /= 2; } return bit; } }