import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] map = new int[N+1]; for (int i = 1; i <= N; i++) { map[i] = Integer.bitCount(i); } int ans = 1; int p = 1; while(p != N) { if (p+map[p] == N) { ans++; break; } else if (p+map[p] < N) { p += map[p]; ans++; } else if (p+map[p] > N && p-map[p] > 0) { p -= map[p]; ans++; } else { ans = -1; break; } if (ans > 1000_000_000) { ans = -1; break; } } System.out.println(ans); } }