Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binary numbers of the form 2^x + p, where x is a non-negative integer.

For example, some -9-binary ("minus nine" binary) numbers are: -8 (minus eight), 7 and 1015 (-8=2^0-9, 7=2^4-9, 1015=2^{10}-9).

The boys now use p-binary numbers to represent everything. They now face a problem: given a positive integer n, what's the smallest number of p-binary numbers (not necessarily distinct) they need to represent n as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.

For example, if p=0 we can represent 7 as 2^0 + 2^1 + 2^2.

And if p=-9 we can represent 7 as one number (2^4-9).

Note that negative p-binary numbers are allowed to be in the sum (see the Notes section for an example).

Input

The only line contains two integers n and p (1 ≤ n ≤ 10^9, -1000 ≤ p ≤ 1000).

Output

If it is impossible to represent n as the sum of any number of p-binary numbers, print a single integer -1. Otherwise, print the smallest possible number of summands.

Examples

Input


24 0


Output


2


Input


24 1


Output


3


Input


24 -1


Output


4


Input


4 -7


Output


2


Input


1 1


Output


-1

Note

0-binary numbers are just regular binary powers, thus in the first sample case we can represent 24 = (2^4 + 0) + (2^3 + 0).

In the second sample case, we can represent 24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1).

In the third sample case, we can represent 24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1). Note that repeated summands are allowed.

In the fourth sample case, we can represent 4 = (2^4 - 7) + (2^1 - 7). Note that the second summand is negative, which is allowed.

In the fifth sample case, no representation is possible.
/*
TO LEARN
1-segment trees
2-euler tour
3-fenwick tree and interval tree
*/
/*
TO SOLVE 
uva 1103
program codeforces edu 102 D
*/
/*
bit manipulation shit
1-Computer Systems: A Programmer's Perspective
2-hacker's delight
3-(02-03-bits-ints)
4-machine-basics
5-Bits Manipulation tutorialspoint
*/
            import java.util.*;
		    import java.math.*;
		    import java.io.*; 
		    import java.util.stream.Collectors;

		     public class A{
		     
		  static InputStream inputStream = System.in;
            static FastScanner scan=new FastScanner();
		     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
static ArrayList<Integer>arr=new ArrayList<Integer>();
static boolean is[]=new boolean[61];
static ArrayList<Long>pows=new ArrayList<Long>();
static boolean rec(int i,long sum,long to,long cur)
{
	
	if(sum==0&&cur==to)
		return true;
	if(sum<=0)
		return false;
	if(i<0)
		return false;
	if(cur>=to)
		return false;
	//System.out.println(pows.get(i)+" "+cur+" "+sum);
	if(rec(i,sum-pows.get(i),to,cur+1)||rec(i-1,sum,to,cur))
		return true;
	return false;
}
static void block(long x)
{
    ArrayList<Integer> v = new ArrayList<Integer>();
     
    // Convert decimal number to
    // its binary equivalent
    //System.out.print("Blocks for "+x+" : ");
    while (x > 0)
    {
        v.add((int)x % 2);
        x = x / 2;
    }
 
    // Displaying the output when
    // the bit is '1' in binary
    // equivalent of number.
    for (int i = 0; i < v.size(); i++)
    {
        if (v.get(i) == 1)
        {
        arr.add(i);
           
        }
    }

}

static Pair cnt(int x)
{
	int res=0,fir=0;
	while(x>0)
	{
		//out.println(x);
		if((x&1)!=0){
		 // x^=1;
			res++;
		}
		x/=2;
		fir++;
	}
	return new Pair(res,fir);
}
	public static void main(String[] args)  throws Exception 
      {
	
		 //scan=new FastScanner("pairup.in");
		 //out = new PrintWriter("pairup.out");
		 
		 /*
		 currently doing 
		 1-digit dp
		 2-ds like fenwick and interval tree and sparse table 
		 */
		 /*
		 READING 
		 1-Everything About Dynamic Programming codeforces
		 2-DYNAMIC PROGRAMMING: FROM NOVICE TO ADVANCED topcoder
		 */


		    int tt=1;

for(long i=0;i<=31;i++)
	pows.add(pow(2,i));
//System.out.println(rec(pows.size()-1,25,2,0));
//tt=scan.nextInt();
//System.out.println(1&1);
int T=1;
		    
	 outer:while(tt-->0)
		    {
		    	int n=scan.nextInt();
		    int p=scan.nextInt();
		    	if(p==0)
		    	{
		    		block(n);
		    		out.println(arr.size());
		    		out.close();
		    		return;
		    	}

		   // block(27);
		    //	out.println(arr);

		    	int res=Integer.MAX_VALUE;
		    	for(int i=1;i<1001;i++){
		    		//if(i==4)
		    		//	out.println(n-(p*i));
		    		if(n-(p*i)>0)
		    		{
		    			//out.println(cnt(n-(p*i)).y+" "+(n-(p*i))+" "+i);
		    			if(i>=cnt(n-(p*i)).x&&i<=cnt(n-(p*i)).y)
		    			{
		    				out.println(i);
		    				out.close();
		    				return;
		    			}
		    		
		    		}

		    	}
		    		//if(res==Integer.MAX_VALUE)
		    		out.println(-1);
		    	// out.println(res);
		    	


		  
		 }
		  	    out.close();
		    	 		  
		   
		}
		static class special{
			char x,y;
			//int id;
			special(char x,char y)
			{
				this.x=x;
				this.y=y;
				//this.id=id;
			}
			@Override
			    public int hashCode() {
		                return (int)(x + 31 * y);
		            }
		              @Override
		            public boolean equals(Object o){
		                if (o == this) return true;
		                if (o.getClass() != getClass()) return false;
		                special t = (special)o;
		                return t.x == x && t.y == y;
		            }
		}

		   
		     static long binexp(long a,long n)
		    {
		        if(n==0)
		            return 1;
		        long res=binexp(a,n/2);
		        if(n%2==1)
		            return res*res*a;
		        else 
		            return res*res;
		    }
		     
		    static long powMod(long base, long exp, long mod) {
		           if (base == 0 || base == 1) return base;
		           if (exp == 0) return 1;
		           if (exp == 1) return (base % mod+mod)%mod;
		           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
		           R *= R;
		           R %= mod;
		           if ((exp & 1) == 1) {
		               return (base * R % mod+mod)%mod;
		           }
		           else return (R %mod+mod)%mod;
		       }
		    static double dis(double x1,double y1,double x2,double y2)
		    {
		        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		    }
		    static long mod(long x,long y)
		        {
		            if(x<0)
		                x=x+(-x/y+1)*y;
		            return x%y;
		        }
		     public static  long pow(long b, long e) {
		                long r = 1;
		                while (e > 0) {
		                    if (e % 2 == 1) r = r * b ;
		                    b = b * b;
		                    e >>= 1;
		                }
		                return r;
		            }
		    private static void sort(int[] arr) {
		            List<Integer> list = new ArrayList<>();
		            for (int object : arr) list.add(object);
		            Collections.sort(list);
		        //Collections.reverse(list);
		            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
		        }
		    private static void sort2(long[] arr) {
		            List<Long> list = new ArrayList<>();
		            for (Long object : arr) list.add(object);
		            Collections.sort(list);
		        Collections.reverse(list);
		            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
		        }
		     static class FastScanner
{
    private int BS = 1 << 16;
    private char NC = (char) 0;
    private byte[] buf = new byte[BS];
    private int bId = 0, size = 0;
    private char c = NC;
    private double cnt = 1;
    private BufferedInputStream in;
 
    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }
 
    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        } catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }
 
    private char getChar() {
        while (bId == size) {
            try {
                size = in.read(buf);
            } catch (Exception e) {
                return NC;
            }
            if (size == -1) return NC;
            bId = 0;
        }
        return (char) buf[bId++];
    }
 
    public int nextInt() {
        return (int) nextLong();
    }
 
    public int[] nextInts(int N) {
        int[] res = new int[N];
        for (int i = 0; i < N; i++) {
            res[i] = (int) nextLong();
        }
        return res;
    }
 
    public long[] nextLongs(int N) {
        long[] res = new long[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextLong();
        }
        return res;
    }
 
    public long nextLong() {
        cnt = 1;
        boolean neg = false;
        if (c == NC) c = getChar();
        for (; (c < '0' || c > '9'); c = getChar()) {
            if (c == '-') neg = true;
        }
        long res = 0;
        for (; c >= '0' && c <= '9'; c = getChar()) {
            res = (res << 3) + (res << 1) + c - '0';
            cnt *= 10;
        }
        return neg ? -res : res;
    }
 
    public double nextDouble() {
        double cur = nextLong();
        return c != '.' ? cur : cur + nextLong() / cnt;
    }
 
    public double[] nextDoubles(int N) {
        double[] res = new double[N];
        for (int i = 0; i < N; i++) {
            res[i] = nextDouble();
        }
        return res;
    }
 
    public String next() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c > 32) {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }
 
    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while (c <= 32) c = getChar();
        while (c != '\n') {
            res.append(c);
            c = getChar();
        }
        return res.toString();
    }
 
    public boolean hasNext() {
        if (c > 32) return true;
        while (true) {
            c = getChar();
            if (c == NC) return false;
            else if (c > 32) return true;
        }
    }
}

		     static class Pair implements Comparable<Pair>{
		            public long x, y,z;
		            public Pair(long x1, long y1,long z1) {
		                x=x1;
		                y=y1;
		                z=z1;
		            }
		             public Pair(long x1, long y1) {
		                x=x1;
		                y=y1;
		    
		            }
		            
		            @Override
		            public int hashCode() {
		                return (int)(x + 31 * y);
		            }
		            public String toString() {
		                return x + " " + y+" "+z;
		            }
		            @Override
		            public boolean equals(Object o){
		                if (o == this) return true;
		                if (o.getClass() != getClass()) return false;
		                Pair t = (Pair)o;
		                return t.x == x && t.y == y&&t.z==z;
		            }
		    public int compareTo(Pair o)
		    {
		    
		    	return (int)(y-o.y);
		     
		        }
		     
		    }
		    
		    }

		     
