import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); if (N == 1) { System.out.println(0); return; } int[] map = new int[N+1]; for (int i = 1; i <= N; i++) { map[i] = Integer.bitCount(i); } boolean[] comp = new boolean[N+1]; for (int i = 1; i < N; i++) { int p = i; while(p < N) { if (p+map[p] == N) { comp[i] = true; } p += map[p]; } } int p = 1; int count = 1; int min = Integer.MAX_VALUE; while(p < N) { if (!comp[p] && p-map[p] > 0 && comp[p-map[p]]) { int tmpCount = count+1; int tmpP = p-map[p]; while(tmpP != N) { tmpCount++; tmpP += map[tmpP]; } min = Math.min(min, tmpCount); } count++; if (p+map[p] == N) { min = Math.min(min, count); } p += map[p]; } System.out.println(min == Integer.MAX_VALUE ? -1 : min); } }