import java.util.*; import java.util.Arrays; public class Main { static int[] isOk = new int[10000]; static int n; public static void main(String[] args){ Arrays.fill(isOk, 0); Scanner sc = new Scanner(System.in); n = sc.nextInt(); isOk[0] = 1; check(1); if(isOk[n-1]==0){ System.out.println(-1); }else{ System.out.println(isOk[n-1]); } } static void check(int x){ int sum = 0; int xx = x; do{ sum += xx%2; xx = xx/2; }while(xx>0); if(x+sum<=n){ if(isOk[x+sum-1]==0){ isOk[x+sum-1]=isOk[x-1]+1; check(x+sum); } } if(x-sum>0){ if(isOk[x-sum-1]==0){ isOk[x-sum-1]=isOk[x-1]+1; check(x-sum); } } } }