import java.util.HashSet; import java.util.Iterator; import java.util.Scanner; import java.util.Set; public class No3 { public static void main(String[] args) { // 標準入力から読み込む際に、Scannerオブジェクトを使う。 Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int ans = 1; Set oldNo = new HashSet<>(); Set nowNo = new HashSet<>(); Set nextNo = new HashSet<>(); nowNo.add(1); oldNo.add(1); while (ans != 10000) { if (nowNo.contains(n)) { System.out.println(ans); return; } for(Iterator iterator = nowNo.iterator(); iterator.hasNext(); ) { Integer value = iterator.next(); int i = value; int s = 0; while (i > 0) { s += i%2; i/=2; } if (!oldNo.contains(value + s)) { nextNo.add(value + s); oldNo.add(value + s); } if (!oldNo.contains(value - s)) { nextNo.add(value - s); oldNo.add(value - s); } } nowNo = nextNo; nextNo = new HashSet<>(); ans++; } System.out.println("-1"); } }