import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int [] c = new int [N+1]; c[1]=1; Queue q = new LinkedList<>(); q.add(1); while(!q.isEmpty()){ int t = q.poll(); int p = Integer.bitCount(t); int b = t-p; int f = t+p; if(b>0&&c[b]==0){ c[b]=c[t]+1; q.add(b); } if(f<=N&&c[f]==0){ c[f]=c[t]+1; q.add(f); } } if(c[N]==0)c[N]=-1; System.out.println(c[N]); } }