import java.util.*; public class No3 { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int tmp = 1; int ans = 1; int mov; int loc = 1; while (true) { if (loc == N) break; mov = 0; while (tmp != 0) { mov += tmp & 1; tmp = tmp >> 1; } //System.out.println(ans); if (ans > N) { ans = -1; break; } else if (loc + mov < N + 1) loc += mov; else if (loc - mov > 0) loc -= mov; tmp = loc; ans ++; } System.out.print(ans); } }