import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int n = koko.nextInt();
        boolean[][] goal = new boolean[2*n+1][n+1];
        goal[1][1]=true;
        boolean[] judge = new boolean[n+1];
        judge[1] = true;
        for(int i=1; i<2*n+1; i++){
            for(int j=1; j<n+1; j++){
                if(goal[i][j]){
                    String jud = Integer.toBinaryString(j);
                    char[] num = jud.toCharArray();
                    int count=0;
                    for(int k=0; k<num.length; k++){
                        if(num[k]=='1'){
                            count++;
                        }
                    }
                    if(j+count<n+1&&!judge[j+count]){
                        goal[i+1][j+count]=true;
                        judge[j+count]=true;
                    }
                    if(j-count>1&&!judge[j-count]){
                        goal[i+1][j-count]=true;
                        judge[j-count]=true;
                    }
                }
            }
        }
        boolean flag = false;
        for(int i=1; i<2*n+1; i++){
            if(goal[i][n]){
                System.out.println(i);
                flag=true;
                break;
            }
        }
        if(!flag){
            System.out.println(-1);
        }
        
    }
    
}