import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); boolean[] seen = new boolean[n+1]; seen[0] = true; LinkedList q = new LinkedList<>(); LinkedList next_q = new LinkedList<>(); q.push(1); int turn = 0; boolean flag = false; while(q.size() > 0){ int v = q.pop(); turn++; if(v == n){ flag = true; break; } seen[v] = true; int left = v - getBitCount(v); int right = v + getBitCount(v); if(left > 0 && !seen[left]){ q.push(left); } if(right <= n && !seen[right]){ q.push(right); } } System.out.println(flag ? turn : -1); } private static int getBitCount(int bits){ bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff); } }