import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int[] cource = new int[N + 1]; ArrayList now = new ArrayList(); now.add(1); cource[1] = 1; for (int i = 2; true; i++) { ArrayList next = new ArrayList(); for (int tmp : now) { if (tmp == N) { System.out.println(cource[N]); return; } int bit = bitCount(tmp); if (tmp + bit <= N && cource[tmp + bit] == 0) { cource[tmp + bit] = i; next.add(tmp + bit); } if (tmp + bit >= 1 && cource[tmp - bit] == 0) { cource[tmp - bit] = i; next.add(tmp - bit); } } if (next.isEmpty()) { System.out.println(-1); return; } now = (ArrayList) next.clone(); } } private static int bitCount(int source) { int count = 0; for (int i = 8192; source > 0; i = i / 2) { if (source >= i) { source -= i; count++; } } return count; } }