import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] visited = new boolean[n]; visited[0] = true; int searchList[] = new int[n]; int countTable[] = new int[n]; countTable[0] = 1; countTable[n-1] = n+1; searchList[0] = 1; int j = 1; int k = 0; while (searchList[k] != 0) { int move = 0; int i = searchList[k]; int count = countTable[k]; while (i < n) { visited[i] = true; move = Integer.bitCount(i); if (visited[i - move]) { i += move; count++; if (i == n) { countTable[n-1] = Math.min (count, countTable[n-1]); } } else { if (i - move >= 0) { searchList[j] = (i - move); visited[i - move] = true; countTable[j] = count + 1; j++; } } } k++; } if (countTable[n-1] == (n+1)) { System.out.println("-1"); } else { System.out.println(countTable[n-1]); } } }