import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int goal = sc.nextInt(); sc.close(); int moveCount = 1; int currentPos = 1; List moveHistory = new ArrayList(); while (true) { if (goal == currentPos) { break; } if (moveHistory.contains(currentPos)) { moveCount = -1; break; } moveHistory.add(currentPos); // dice! int dice = int2bit1count(currentPos); if (goal > currentPos + dice) { currentPos += dice; } else { currentPos -= dice; } moveCount++; } System.out.println(moveCount); } public static int int2bit1count(Integer num) { String bitStr = Integer.toBinaryString(num); return bitStr.replace("0", "").length(); } }