import java.util.*; class BitSugoroku { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); ArrayList root = new ArrayList(); for (int i = 1; i < n;) { int mv = Integer.bitCount(i); int go = i + mv; int back = i - mv; if (go <= n) { i = go; root.add(go); } else { if (root.contains(back)) { root.clear(); break; } i = back; root.add(back); } } System.out.println(root.size() != 0 ? root.size() + 1 : -1); } }