import java.util.*; import javax.naming.directory.SearchResult; public class Main2 { 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[1] = 1; searchList[1] = 1; int j = 2; int k = 1; while (searchList[k] != 0) { //System.out.println("new Root"); 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++; //System.out.println(i); if (i == n) { System.out.println(count); return; } } else { if (i - move >= 0) { searchList[j] = (i - move); //System.out.println("add SearchList"); //System.out.println(i-move); visited[i - move] = true; countTable[j] = count + 1; j++; } } } k++; } System.out.println("-1"); return; } }