import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); boolean [] boo = new boolean [N+1]; int [] c = new int [N+1]; for(int i=2; i<=N; i++){ c[i]=Integer.MAX_VALUE; } 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]=Math.min(c[b],c[t]+1); if(boo[b]==false)q.add(b); boo[b]=true; } if(f<=N){ c[f]=Math.min(c[f],c[t]+1); if(boo[f]==false)q.add(f); boo[f]=true; } } if(c[N]==0)c[N]=-1; System.out.println(c[N]); } }