import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> fin = new HashSet<>();
        Queue<Integer> target = new ArrayDeque<>();
        Queue<Integer> cntQ = new ArrayDeque<>();
        target.add(1);
        cntQ.add(1);
        while (!target.isEmpty()){
            int now = target.poll();
            if(now==n){
                System.out.println(cntQ.poll());
                return;
            }
            fin.add(now);
            int bit = Integer.bitCount(now);
            int cnt = cntQ.poll();
            if(now-bit>=1 && !fin.contains(now-bit)){target.add(now-bit);cntQ.add(cnt+1);}
            if(now+bit<=n && !fin.contains(now+bit)){target.add(now+bit);cntQ.add(cnt+1);}
        }
        System.out.println(-1);
    }
}