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).

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

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.

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.

var n,p,i:longint;
function count(x:longint):longint;
var tot:longint;
begin
  tot:=0;
  while x>0 do
  begin
    if (x and 1)>0 then inc(tot);
    x:=x div 2;
  end;
  exit(tot);
end;
begin
  readln(n,p);
  for i:=1 to 31 do
    if (n-i*p>=i) and (count(n-i*p)<=i) then begin writeln(i);exit;end;
  writeln(-1);
end.

                                             const eps=1e-12;
                          besk=2002000000000000000; label 4,1,3,2,44,22;
                    type mas=array[-100..1200000+1] of int64;
                    integer=longint;    zap=record p1,p2,p3:int64; end;
                    zap1=^zap;
                    var sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                    ss3,ss,ss1,ss2:string;
                    qqq:zap;  pmin,bet,al:extended;
                    ot1,ot2:zap;
                    ver:array[-1..500,-1..5] of extended;
                    verugad:array[-2..200,-2..200,-2..200] of extended;
                    vhod,kolzan,qq,kol,chisl,znam,n,m,ttt,right,left,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,sum,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
                      z,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                     vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                      zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                      ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                      ppole:array[-1000000..3000000] of char;
                      str1,str2,stroka:array[-1000..1000000] of char;
                      dinam:array[-100000..1000000] of extended;
                      t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
                      dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                      sp,sss:array[-10..2000000] of string;
                      newpole,pole:array[-1..2100,-1..2700] of char;
                      blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                      poss:int64;
                      ch:char;
                      ff,flagg1:boolean;
                      oldx,oldy,zz,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..400002] of int64;
                      dddd:array[-10..5010,-10..5010] of int64;
                     function srav(i,j:longint):boolean; label 44;

                    begin
                       if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                       if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                       if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;

                     44:
                    end;

                    procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                    begin
                    i:=l;j:=m; flag:=true; step:=0;while flag do begin
                    if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                    inc(step);inc(i);
                    {writeln('step=',step,' i=',i);} end;
                    if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                    inc(step);inc(j);end;
                    if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                    end;
                    if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                    if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                    end;
                    procedure sort(var c:mas);

                    begin

                    k:=1; repeat
                    l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                    for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                    until (k>=n);

                    end;

                    function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                    function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                    function min3(a,b,c:int64):int64;  var ot:int64;
                    begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

          function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
      tt:zap; tt1:zap1;  fl:boolean;
    begin
      fl:=false;
      if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
      x2:=1;x1:=0;y2:=0;y1:=1;
      while b>0 do
        begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
              a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
        end;
        if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
             begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
       evkl:=tt1;
    end;

                    function phi(a,b:double):double; label 222;var p:double;
                    begin
                      if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                      if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                      if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                      if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                      if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                      222: phi:=p;
                    end;

                    function nod(a,b:int64):int64; var p,t:int64;
                    begin
                      a:=abs(a); b:=abs(b);
                      if (a>0)and(b>0) then
                       begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                        p:=a;
                       end else if a=0 then p:=b else p:=a;
                    nod:=p;
                    end;
              function arccos(tt:extended):extended;
      begin
        if abs(tt)>1-1e-13 then
        if tt>0 then  arccos:=0 else arccos:=pi;
        if tt=0 then arccos:=pi/2 else
        if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
        else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

      end;

                    function nok(a,b:int64):int64;
                    begin  nok:=(a*b) div nod(a,b);  end;

                       function degg(a:int64;k:int64):int64; var p:int64;
                    begin
                     if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                       begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                    end;

          {          function zaprmax(left,right:longint):int64;
                begin
                   if left>=right then zaprmax:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                         begin
                          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                         end;

                     end;

                end;
           }
              function zaprmin(left,right:longint):int64;
                begin
                   if left>=right then zaprmin:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
                         begin
                          if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
                          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

                         end;

                     end;

                end;

                    procedure udal(ii:longint);
                    begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                    function nomerr(gr:int64):int64;

                    var ot,aa,bb,cc:int64; fl:boolean;
                    begin
                      aa:=1; bb:=p;  cc:=aa; fl:=false;
                      while abs(aa-bb)>1 do
                        begin
                           cc:=(aa+bb) shr 1;
                           writeln('cc=++ ',cc);
                           if y[cc]<gr then aa:=cc else bb:=cc;

                        end;
                       writeln(' cc= ',cc);
                     {  cc:=max(cc-3,0);
                     }  repeat inc(cc) until y[cc]>=gr;
                       if y[cc]=gr then fl:=true else fl:=false;
                        if fl then nomerr:=a1[cc] else nomerr:=-1000;
                       nomerr:=cc;
                    end;

                    function pprost(pp:longint):boolean;
                    var i,j,t:longint; tt:extended; fl:boolean;
                    begin
                      tt:=pp;
                      tt:=sqrt(tt);
                      fl:=true;
                      for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                     pprost:=fl;

                    end;

                    function gl(c:char):boolean;
                    begin
                     if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                    end;

    function koled(t:int64):longint;
    var p,i,j,ans:longint;
    begin
       ans:=0;
       while t>0 do begin ans:=ans+t and 1; t:=t shr 1;  end;
       koled:=ans;
    end;

     begin
      {  assign (input,'D:\Projects\input.txt');reset(input);
          assign (output,'D:\Projects\output.txt'); rewrite(output);
       }
          read(vhod,p);
          z[0]:=1;
          for i:=1 to 32 do z[i]:=z[i-1]*2;
          for i:=1 to 32 do z[i]:=z[i]+p;

        {  for i:=1 to 20 do writeln(i,' ',koled(i));
        }    ans:=100000000000000;
          for step:=0 to 100000 do
             begin
               ii:=step;
               t:=vhod-ii*p;

             if t>0 then
              begin
                { writeln('t= ',t,'  koled= ',koled(t));
                } if (koled(t)<=step)and(step<=t) then ans:=min(ans,step);
              end;
             end;

           if ans<10000000000 then write(ans) else write(-1);

          1: close (output);
        end.

                                             const eps=1e-12;
                          besk=2002000000000000000; label 4,1,3,2,44,22;
                    type mas=array[-100..1200000+1] of int64;
                    integer=longint;    zap=record p1,p2,p3:int64; end;
                    zap1=^zap;
                    var sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                    ss3,ss,ss1,ss2:string;
                    qqq:zap;  pmin,bet,al:extended;
                    ot1,ot2:zap;
                    ver:array[-1..500,-1..5] of extended;
                    verugad:array[-2..200,-2..200,-2..200] of extended;
                    vhod,kolzan,qq,kol,chisl,znam,n,m,ttt,right,left,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,sum,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
                      z,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                     vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                      zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                      ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                      ppole:array[-1000000..3000000] of char;
                      str1,str2,stroka:array[-1000..1000000] of char;
                      dinam:array[-100000..1000000] of extended;
                      t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
                      dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                      sp,sss:array[-10..2000000] of string;
                      newpole,pole:array[-1..2100,-1..2700] of char;
                      blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                      poss:int64;
                      ch:char;
                      ff,flagg1:boolean;
                      oldx,oldy,zz,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..400002] of int64;
                      dddd:array[-10..5010,-10..5010] of int64;
                     function srav(i,j:longint):boolean; label 44;

                    begin
                       if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                       if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                       if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;

                     44:
                    end;

                    procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                    begin
                    i:=l;j:=m; flag:=true; step:=0;while flag do begin
                    if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                    inc(step);inc(i);
                    {writeln('step=',step,' i=',i);} end;
                    if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                    inc(step);inc(j);end;
                    if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                    end;
                    if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                    if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                    end;
                    procedure sort(var c:mas);

                    begin

                    k:=1; repeat
                    l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                    for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                    until (k>=n);

                    end;

                    function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                    function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                    function min3(a,b,c:int64):int64;  var ot:int64;
                    begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

          function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
      tt:zap; tt1:zap1;  fl:boolean;
    begin
      fl:=false;
      if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
      x2:=1;x1:=0;y2:=0;y1:=1;
      while b>0 do
        begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
              a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
        end;
        if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
             begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
       evkl:=tt1;
    end;

                    function phi(a,b:double):double; label 222;var p:double;
                    begin
                      if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                      if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                      if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                      if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                      if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                      222: phi:=p;
                    end;

                    function nod(a,b:int64):int64; var p,t:int64;
                    begin
                      a:=abs(a); b:=abs(b);
                      if (a>0)and(b>0) then
                       begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                        p:=a;
                       end else if a=0 then p:=b else p:=a;
                    nod:=p;
                    end;
              function arccos(tt:extended):extended;
      begin
        if abs(tt)>1-1e-13 then
        if tt>0 then  arccos:=0 else arccos:=pi;
        if tt=0 then arccos:=pi/2 else
        if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
        else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

      end;

                    function nok(a,b:int64):int64;
                    begin  nok:=(a*b) div nod(a,b);  end;

                       function degg(a:int64;k:int64):int64; var p:int64;
                    begin
                     if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                       begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                    end;

          {          function zaprmax(left,right:longint):int64;
                begin
                   if left>=right then zaprmax:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                         begin
                          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                         end;

                     end;

                end;
           }
              function zaprmin(left,right:longint):int64;
                begin
                   if left>=right then zaprmin:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
                         begin
                          if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
                          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

                         end;

                     end;

                end;

                    procedure udal(ii:longint);
                    begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                    function nomerr(gr:int64):int64;

                    var ot,aa,bb,cc:int64; fl:boolean;
                    begin
                      aa:=1; bb:=p;  cc:=aa; fl:=false;
                      while abs(aa-bb)>1 do
                        begin
                           cc:=(aa+bb) shr 1;
                           writeln('cc=++ ',cc);
                           if y[cc]<gr then aa:=cc else bb:=cc;

                        end;
                       writeln(' cc= ',cc);
                     {  cc:=max(cc-3,0);
                     }  repeat inc(cc) until y[cc]>=gr;
                       if y[cc]=gr then fl:=true else fl:=false;
                        if fl then nomerr:=a1[cc] else nomerr:=-1000;
                       nomerr:=cc;
                    end;

                    function pprost(pp:longint):boolean;
                    var i,j,t:longint; tt:extended; fl:boolean;
                    begin
                      tt:=pp;
                      tt:=sqrt(tt);
                      fl:=true;
                      for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                     pprost:=fl;

                    end;

                    function gl(c:char):boolean;
                    begin
                     if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                    end;

    function koled(t:int64):longint;
    var p,i,j,ans:longint;
    begin
       ans:=0;
       while t>0 do begin ans:=ans+t and 1; t:=t shr 1;  end;
       koled:=ans;
    end;

     begin
      {  assign (input,'D:\Projects\input.txt');reset(input);
          assign (output,'D:\Projects\output.txt'); rewrite(output);
       }
          read(vhod,p);
          z[0]:=1;
          for i:=1 to 32 do z[i]:=z[i-1]*2;
          for i:=1 to 32 do z[i]:=z[i]+p;

        {  for i:=1 to 20 do writeln(i,' ',koled(i));
        }    ans:=100000000000000;
          for step:=0 to 1000000 do
             begin
               ii:=step;
               t:=vhod-ii*p;

             if t>0 then
              begin
                { writeln('t= ',t,'  koled= ',koled(t));
                } if (koled(t)<=step)and(step<=t) then ans:=min(ans,step);
              end;
             end;

           if ans<10000000000 then write(ans) else write(-1);

          1: close (output);
        end.

                                             const eps=1e-12;
                          besk=2002000000000000000; label 4,1,3,2,44,22;
                    type mas=array[-100..1200000+1] of int64;
                    integer=longint;    zap=record p1,p2,p3:int64; end;
                    zap1=^zap;
                    var sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                    ss3,ss,ss1,ss2:string;
                    qqq:zap;  pmin,bet,al:extended;
                    ot1,ot2:zap;
                    ver:array[-1..500,-1..5] of extended;
                    verugad:array[-2..200,-2..200,-2..200] of extended;
                    vhod,kolzan,qq,kol,chisl,znam,n,m,ttt,right,left,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,sum,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
                      z,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                     vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                      zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                      ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                      ppole:array[-1000000..3000000] of char;
                      str1,str2,stroka:array[-1000..1000000] of char;
                      dinam:array[-100000..1000000] of extended;
                      t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
                      dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                      sp,sss:array[-10..2000000] of string;
                      newpole,pole:array[-1..2100,-1..2700] of char;
                      blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                      poss:int64;
                      ch:char;
                      ff,flagg1:boolean;
                      oldx,oldy,zz,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..400002] of int64;
                      dddd:array[-10..5010,-10..5010] of int64;
                     function srav(i,j:longint):boolean; label 44;

                    begin
                       if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                       if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                       if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;

                     44:
                    end;

                    procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                    begin
                    i:=l;j:=m; flag:=true; step:=0;while flag do begin
                    if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                    inc(step);inc(i);
                    {writeln('step=',step,' i=',i);} end;
                    if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                    inc(step);inc(j);end;
                    if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                    end;
                    if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                    if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                    end;
                    procedure sort(var c:mas);

                    begin

                    k:=1; repeat
                    l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                    for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                    until (k>=n);

                    end;

                    function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                    function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                    function min3(a,b,c:int64):int64;  var ot:int64;
                    begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

          function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
      tt:zap; tt1:zap1;  fl:boolean;
    begin
      fl:=false;
      if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
      x2:=1;x1:=0;y2:=0;y1:=1;
      while b>0 do
        begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
              a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
        end;
        if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
             begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
       evkl:=tt1;
    end;

                    function phi(a,b:double):double; label 222;var p:double;
                    begin
                      if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                      if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                      if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                      if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                      if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                      222: phi:=p;
                    end;

                    function nod(a,b:int64):int64; var p,t:int64;
                    begin
                      a:=abs(a); b:=abs(b);
                      if (a>0)and(b>0) then
                       begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                        p:=a;
                       end else if a=0 then p:=b else p:=a;
                    nod:=p;
                    end;
              function arccos(tt:extended):extended;
      begin
        if abs(tt)>1-1e-13 then
        if tt>0 then  arccos:=0 else arccos:=pi;
        if tt=0 then arccos:=pi/2 else
        if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
        else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

      end;

                    function nok(a,b:int64):int64;
                    begin  nok:=(a*b) div nod(a,b);  end;

                       function degg(a:int64;k:int64):int64; var p:int64;
                    begin
                     if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                       begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                    end;

          {          function zaprmax(left,right:longint):int64;
                begin
                   if left>=right then zaprmax:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                         begin
                          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                         end;

                     end;

                end;
           }
              function zaprmin(left,right:longint):int64;
                begin
                   if left>=right then zaprmin:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
                         begin
                          if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
                          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

                         end;

                     end;

                end;

                    procedure udal(ii:longint);
                    begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                    function nomerr(gr:int64):int64;

                    var ot,aa,bb,cc:int64; fl:boolean;
                    begin
                      aa:=1; bb:=p;  cc:=aa; fl:=false;
                      while abs(aa-bb)>1 do
                        begin
                           cc:=(aa+bb) shr 1;
                           writeln('cc=++ ',cc);
                           if y[cc]<gr then aa:=cc else bb:=cc;

                        end;
                       writeln(' cc= ',cc);
                     {  cc:=max(cc-3,0);
                     }  repeat inc(cc) until y[cc]>=gr;
                       if y[cc]=gr then fl:=true else fl:=false;
                        if fl then nomerr:=a1[cc] else nomerr:=-1000;
                       nomerr:=cc;
                    end;

                    function pprost(pp:longint):boolean;
                    var i,j,t:longint; tt:extended; fl:boolean;
                    begin
                      tt:=pp;
                      tt:=sqrt(tt);
                      fl:=true;
                      for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                     pprost:=fl;

                    end;

                    function gl(c:char):boolean;
                    begin
                     if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                    end;

    function koled(t:int64):longint;
    var p,i,j,ans:longint;
    begin
       ans:=0;
       while t>0 do begin ans:=ans+t and 1; t:=t shr 1;  end;
       koled:=ans;
    end;

     begin
      {  assign (input,'D:\Projects\input.txt');reset(input);
          assign (output,'D:\Projects\output.txt'); rewrite(output);
       }
          read(vhod,p);
          z[0]:=1;
          for i:=1 to 32 do z[i]:=z[i-1]*2;
          for i:=1 to 32 do z[i]:=z[i]+p;

        {  for i:=1 to 20 do writeln(i,' ',koled(i));
        }    ans:=100000000000000;
          for step:=0 to 10000000 do
             begin
               ii:=step;
               t:=vhod-ii*p;

             if t>0 then
              begin
                { writeln('t= ',t,'  koled= ',koled(t));
                } if (koled(t)<=step)and(step<=t) then ans:=min(ans,step);
              end;
             end;

           if ans<10000000000 then write(ans) else write(-1);

          1: close (output);
        end.

var
  c, d, e, n, p, n1: integer;

begin
  read(n, p);
  c := 0;
  while n = n do
  begin
    n := n - p;
    c := c + 1;
    d := 1;
    while d <= n do d := d * 2;
    n1 := n;
    e := 0;
    while n1 > 0 do
    begin
      if d <= n1 then
      begin
        n1 := n1 - d;
        e := e + 1;
      end;
      d := d div 2;
    end;
    if (n < c) then
    begin
      write('-1');
      break;
    end
    else if e <= c then
    begin
      write(c);
      break;
    end;
  end;
end.

var n,p,i:longint;
function count(x:longint):longint;
var tot:longint;
begin
  tot:=0;
  while x>0 do
  begin
    if (x and 1)>0 then inc(tot);
    x:=x div 2;
  end;
  exit(tot);
end;
begin
  readln(n,p);
  for i:=1 to 31 do
    if (n-i*p>0) and (count(n-i*p)<=i) then begin writeln(i);exit;end;
  writeln(-1);
end.

                                             const eps=1e-12;
                          besk=2002000000000000000; label 4,1,3,2,44,22;
                    type mas=array[-100..1200000+1] of int64;
                    integer=longint;    zap=record p1,p2,p3:int64; end;
                    zap1=^zap;
                    var sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                    ss3,ss,ss1,ss2:string;
                    qqq:zap;  pmin,bet,al:extended;
                    ot1,ot2:zap;
                    ver:array[-1..500,-1..5] of extended;
                    verugad:array[-2..200,-2..200,-2..200] of extended;
                    vhod,kolzan,qq,kol,chisl,znam,n,m,ttt,right,left,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,sum,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
                      z,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                     vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                      zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                      ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                      ppole:array[-1000000..3000000] of char;
                      str1,str2,stroka:array[-1000..1000000] of char;
                      dinam:array[-100000..1000000] of extended;
                      t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
                      dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                      sp,sss:array[-10..2000000] of string;
                      newpole,pole:array[-1..2100,-1..2700] of char;
                      blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                      poss:int64;
                      ch:char;
                      ff,flagg1:boolean;
                      oldx,oldy,zz,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..400002] of int64;
                      dddd:array[-10..5010,-10..5010] of int64;
                     function srav(i,j:longint):boolean; label 44;

                    begin
                       if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                       if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                       if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;

                     44:
                    end;

                    procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                    begin
                    i:=l;j:=m; flag:=true; step:=0;while flag do begin
                    if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                    inc(step);inc(i);
                    {writeln('step=',step,' i=',i);} end;
                    if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                    inc(step);inc(j);end;
                    if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                    end;
                    if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                    if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                    end;
                    procedure sort(var c:mas);

                    begin

                    k:=1; repeat
                    l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                    for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                    until (k>=n);

                    end;

                    function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                    function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                    function min3(a,b,c:int64):int64;  var ot:int64;
                    begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

          function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
      tt:zap; tt1:zap1;  fl:boolean;
    begin
      fl:=false;
      if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
      x2:=1;x1:=0;y2:=0;y1:=1;
      while b>0 do
        begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
              a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
        end;
        if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
             begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
       evkl:=tt1;
    end;

                    function phi(a,b:double):double; label 222;var p:double;
                    begin
                      if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                      if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                      if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                      if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                      if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                      222: phi:=p;
                    end;

                    function nod(a,b:int64):int64; var p,t:int64;
                    begin
                      a:=abs(a); b:=abs(b);
                      if (a>0)and(b>0) then
                       begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                        p:=a;
                       end else if a=0 then p:=b else p:=a;
                    nod:=p;
                    end;
              function arccos(tt:extended):extended;
      begin
        if abs(tt)>1-1e-13 then
        if tt>0 then  arccos:=0 else arccos:=pi;
        if tt=0 then arccos:=pi/2 else
        if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
        else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

      end;

                    function nok(a,b:int64):int64;
                    begin  nok:=(a*b) div nod(a,b);  end;

                       function degg(a:int64;k:int64):int64; var p:int64;
                    begin
                     if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                       begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                    end;

          {          function zaprmax(left,right:longint):int64;
                begin
                   if left>=right then zaprmax:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                         begin
                          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                         end;

                     end;

                end;
           }
              function zaprmin(left,right:longint):int64;
                begin
                   if left>=right then zaprmin:=y[left] else
                     begin
                        if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
                         begin
                          if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
                          if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

                         end;

                     end;

                end;

                    procedure udal(ii:longint);
                    begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                    function nomerr(gr:int64):int64;

                    var ot,aa,bb,cc:int64; fl:boolean;
                    begin
                      aa:=1; bb:=p;  cc:=aa; fl:=false;
                      while abs(aa-bb)>1 do
                        begin
                           cc:=(aa+bb) shr 1;
                           writeln('cc=++ ',cc);
                           if y[cc]<gr then aa:=cc else bb:=cc;

                        end;
                       writeln(' cc= ',cc);
                     {  cc:=max(cc-3,0);
                     }  repeat inc(cc) until y[cc]>=gr;
                       if y[cc]=gr then fl:=true else fl:=false;
                        if fl then nomerr:=a1[cc] else nomerr:=-1000;
                       nomerr:=cc;
                    end;

                    function pprost(pp:longint):boolean;
                    var i,j,t:longint; tt:extended; fl:boolean;
                    begin
                      tt:=pp;
                      tt:=sqrt(tt);
                      fl:=true;
                      for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                     pprost:=fl;

                    end;

                    function gl(c:char):boolean;
                    begin
                     if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                    end;

    function koled(t:int64):longint;
    var p,i,j,ans:longint;
    begin
       ans:=0;
       while t>0 do begin ans:=ans+t and 1; t:=t shr 1;  end;
       koled:=ans;
    end;

     begin
      {  assign (input,'D:\Projects\input.txt');reset(input);
          assign (output,'D:\Projects\output.txt'); rewrite(output);
       }
          read(vhod,p);
          z[0]:=1;
          for i:=1 to 32 do z[i]:=z[i-1]*2;
          for i:=1 to 32 do z[i]:=z[i]+p;

        {  for i:=1 to 20 do writeln(i,' ',koled(i));
        }    ans:=100000000000000;
          for step:=0 to 10000000 do
             begin
               ii:=step;
               t:=vhod-ii*p;

             if t>0 then
              begin
                { writeln('t= ',t,'  koled= ',koled(t));
                } if koled(t)<=step then ans:=min(ans,step);
              end;
             end;

           if ans<10000000000 then write(ans) else write(-1);

          1: close (output);
        end.

                                  const eps=1e-12;
                      besk=2002000000000000000; label 4,1,3,2,44,22;
                type mas=array[-100..1200000+1] of int64;
                integer=longint;    zap=record p1,p2,p3:int64; end;
                zap1=^zap;
                var sdvig,start,dl,len,i1,j1,mask,stepp,n2,i,j,k,l,step,k1,mesto,num:longint;
                ss3,ss,ss1,ss2:string;
                qqq:zap;  pmin,bet,al:extended;
                ot1,ot2:zap;
                ver:array[-1..500,-1..5] of extended;
                verugad:array[-2..200,-2..200,-2..200] of extended;
                vhod,kolzan,qq,kol,chisl,znam,n,m,ttt,right,left,numpos,vx,vy,ans,up,down,xmin,xmax,ymin,ymax,imax,t3,qq1,qq2,q1,q2,ost,koll,w,pos,dx,dy,sum,finish,time,p3,p4,jj,qqqq,ii,tt,pmax,pmax2,p1,p2,ot,ott,hh,pos0,pos1,pos2,pp,mm,maxot,mnog,tmax,summax,nn,kk,modul,t0,n1,q,t,p:int64; flag1:boolean;
                  z,a2,invx,invy,summ,place,str,b2,z1,sum1,sum0,d0,d1,ccc,c,d,a,b:mas; flag2,flag:boolean;  pl:longint;
                 vel,zapas,razn,oldll,oldrr,ppp,shag,posx,posy,minx,miny,maxx,maxy,kolplus,kolminus,razr,jmax,gr,grr,ener,dob,aa,bb,cc,dist,tt3,tt1,tt2,ugg,aa1,aa2,r,ug:int64;
                  zzan,prost,marked,zan:array[-1000000..1000000] of boolean;
                  ll,rr,zpl,zmi,path,lx,a3,a4,dd1,dd2,predok,a1,b1,strok:array[-10000..1500000] of int64;
                  ppole:array[-1000000..3000000] of char;
                  str1,str2,stroka:array[-1000..1000000] of char;
                  dinam:array[-100000..1000000] of extended;
                  t1,t2,al1,bet1,cosa,sina,cosb,sinb,rx,ry,sdvigx,sdvigy,px,py,h1,h2,h,l1,l2,otmax,v:int64;
                  dd,ssumitog,profil,zzz:array[-10..2100,-10..2100] of int64;
                  sp,sss:array[-10..2000000] of string;
                  newpole,pole:array[-1..2100,-1..2700] of char;
                  blizpr,ddd,ddinv,dnech,poschet,posnechet:array[-10..390000,-1..6] of int64;
                  poss:int64;
                  ch:char;
                  ff,flagg1:boolean;
                  oldx,oldy,zz,numx,numy,xleft,xright,s,znach,nomer,newplace,newstr,next,prev,xx,yy,aold,x,y:array[-10000..400002] of int64;
                  dddd:array[-10..5010,-10..5010] of int64;
                 function srav(i,j:longint):boolean; label 44;

                begin
                   if (a[i]<a[j]) then begin srav:=true; goto 44;  end;
                   if a[i]>a[j] then begin  srav:=false; goto 44;   end;
                   if a[i]=a[j] then if a1[i]<a1[j] then srav:=true else srav:=false;

                 44:
                end;

                procedure sl (k,l,m:integer);  {k- dlina, l,m - nachalo dvuh blokov}
                begin
                i:=l;j:=m; flag:=true; step:=0;while flag do begin
                if (srav(i,j)) then begin begin b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];end;
                inc(step);inc(i);
                {writeln('step=',step,' i=',i);} end;
                if (not srav(i,j)) then begin begin b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];end;
                inc(step);inc(j);end;
                if  ((i>=l+k) or (j>=m+k)) then flag:=false;
                end;
                if(i>=l+k) then repeat b[l+step]:=a[j];b1[l+step]:=a1[j];b2[l+step]:=a2[j];inc(step);inc(j);until (j>=m+k);
                if(j>=m+k) then repeat b[l+step]:=a[i];b1[l+step]:=a1[i];b2[l+step]:=a2[i];inc(step);inc(i);until (i>=l+k);
                end;
                procedure sort(var c:mas);

                begin

                k:=1; repeat
                l:=1;m:=k+l; repeat sl(k,l,m); l:=l+2*k;m:=m+2*k; until (l>=n); k:=k*2;
                for i:=1 to n do begin a[i]:=b[i];a1[i]:=b1[i];a2[i]:=b2[i]; end;
                until (k>=n);

                end;

                function min (a,b:int64):int64;begin min:=b;if a<b then min:=a;  end;
                function max (a,b:int64):int64;begin max:=b;if a>b then max:=a;  end;
                function min3(a,b,c:int64):int64;  var ot:int64;
                begin ot:=a; if b<ot then ot:=b; if c<ot then ot:=c;  min3:=ot;  end;

      function evkl(a,b:int64):zap1; var d,x,y,r,q,i,j,k,x1,x2,y1,y2:int64;
  tt:zap; tt1:zap1;  fl:boolean;
begin
  fl:=false;
  if a<b then begin r:=a;a:=b;b:=r; fl:=true; end;
  x2:=1;x1:=0;y2:=0;y1:=1;
  while b>0 do
    begin q:=a div b; r:=a mod b; x:=x2-q*x1;y:=y2-q*y1;
          a:=b;b:=r;x2:=x1;x1:=x;y2:=y1;y1:=y;
    end;
    if not fl then begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=x;tt.p3:=y; tt1:=@tt; end else
         begin d:=a; x:=x2;y:=y2; tt.p1:=d;tt.p2:=y;tt.p3:=x; tt1:=@tt; end;
   evkl:=tt1;
end;

                function phi(a,b:double):double; label 222;var p:double;
                begin
                  if (a>0)and (b>=0) then begin p:=arctan(b/a);goto 222; end;
                  if (a<0) then begin p:=pi+arctan(b/a);goto 222; end;
                  if (a>0)and (b<0) then begin p:=2*pi+arctan(b/a);goto 222; end;
                  if (a=0)and (b>0) then begin p:=pi/2;goto 222; end;
                  if (a=0)and (b<0) then begin p:=3*pi/2;goto 222; end;
                  222: phi:=p;
                end;

                function nod(a,b:int64):int64; var p,t:int64;
                begin
                  a:=abs(a); b:=abs(b);
                  if (a>0)and(b>0) then
                   begin while (b>0) do begin t:=a mod b;a:=b;b:=t;    end;
                    p:=a;
                   end else if a=0 then p:=b else p:=a;
                nod:=p;
                end;
          function arccos(tt:extended):extended;
  begin
    if abs(tt)>1-1e-13 then
    if tt>0 then  arccos:=0 else arccos:=pi;
    if tt=0 then arccos:=pi/2 else
    if abs(tt)<=1-1e-13 then if tt>=0 then arccos:=arctan(sqrt(1-tt*tt)/tt)
    else arccos:=pi+arctan(sqrt(1-tt*tt)/tt);

  end;

                function nok(a,b:int64):int64;
                begin  nok:=(a*b) div nod(a,b);  end;

                   function degg(a:int64;k:int64):int64; var p:int64;
                begin
                 if k<=0 then degg:=1 else if odd(k) then degg:=(degg(a,k-1)*a) mod modul  else
                   begin  p:=degg(a,k div 2); degg:=(p*p) mod modul;    end;

                end;

      {          function zaprmax(left,right:longint):int64;
            begin
               if left>=right then zaprmax:=y[left] else
                 begin
                    if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
                     begin
                      if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
                      if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

                     end;

                 end;

            end;
       }
          function zaprmin(left,right:longint):int64;
            begin
               if left>=right then zaprmin:=y[left] else
                 begin
                    if not odd(left) and odd(right) then zaprmin:=zaprmin(left shr 1,right shr 1) else
                     begin
                      if odd(left) then  zaprmin:=min(zaprmin(left+1,right),y[left]);
                      if not odd(right) then zaprmin:=min(zaprmin(left,right-1),y[right]);

                     end;

                 end;

            end;

                procedure udal(ii:longint);
                begin  next[prev[ii]]:=next[ii];prev[next[ii]]:=prev[ii];  end;

                function nomerr(gr:int64):int64;

                var ot,aa,bb,cc:int64; fl:boolean;
                begin
                  aa:=1; bb:=p;  cc:=aa; fl:=false;
                  while abs(aa-bb)>1 do
                    begin
                       cc:=(aa+bb) shr 1;
                       writeln('cc=++ ',cc);
                       if y[cc]<gr then aa:=cc else bb:=cc;

                    end;
                   writeln(' cc= ',cc);
                 {  cc:=max(cc-3,0);
                 }  repeat inc(cc) until y[cc]>=gr;
                   if y[cc]=gr then fl:=true else fl:=false;
                    if fl then nomerr:=a1[cc] else nomerr:=-1000;
                   nomerr:=cc;
                end;

                function pprost(pp:longint):boolean;
                var i,j,t:longint; tt:extended; fl:boolean;
                begin
                  tt:=pp;
                  tt:=sqrt(tt);
                  fl:=true;
                  for i:=2 to round(tt) do if pp mod i=0 then  fl:=false;

                 pprost:=fl;

                end;

                function gl(c:char):boolean;
                begin
                 if (c='a')or (c='o')or(c='e')or(c='i')or(c='u') then gl:=true else gl:=false;

                end;

function koled(t:int64):longint;
var p,i,j,ans:longint;
begin
   ans:=0;
   while t>0 do begin ans:=ans+t and 1; t:=t shr 1;  end;
   koled:=ans;
end;

 begin
   { assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
    }
      read(vhod,p);
      z[0]:=1;
      for i:=1 to 32 do z[i]:=z[i-1]*2;
      for i:=1 to 32 do z[i]:=z[i]+p;

    {  for i:=1 to 20 do writeln(i,' ',koled(i));
    }    ans:=100000000000000;
      for step:=0 to 1000000 do
         begin
           ii:=step;
           t:=vhod-ii*p;

         if t>0 then
          begin
            { writeln('t= ',t,'  koled= ',koled(t));
            } if koled(t)<=step then begin ans:=min(ans,step); goto 2;  end;
          end;
         end;

   2:    if ans<10000000000 then write(ans) else write(-1);

      1: close (output);
    end.

var
  c, d, e, n, p, n1: integer;

begin
  read(n, p);
  c := 0;
  while n = n do
  begin
    n := n - p;
    c := c + 1;
    d := 1;
    while d <= n do d := d * 2;
    n1 := n;
    e := 0;
    while n1 > 0 do
    begin
      if d <= n1 then
      begin
        n1 := n1 - d;
        e := e + 1;
      end;
      d := d div 2;
    end;
    if (n <= 0) then
    begin
      write('-1');
      break;
    end
    else if e <= c then
    begin
      write(c);
      break;
    end;
  end;
end.

var
  c, d, e, n, p, n1: integer;

begin
  read(n, p);
  c := 0;
  while n = n do
  begin
    n := n - p;
    c := c + 1;
    d := 1;
    while d <= n do d := d * 2;
    n1 := n;
    e := 0;
    while n1 > 0 do
    begin
      if d <= n1 then
      begin
        n1 := n1 - d;
        e := e + 1;
      end;
      d := d div 2;
    end;
    if (n <= 1) then
    begin
      write('-1');
      break;
    end
    else if e <= c then
    begin
      write(c);
      break;
    end;
  end;
end.

var
  c, d, e, n, p, n1: integer;

begin
  read(n, p);
  c := 0;
  while n = n do
  begin
    n := n - p;
    c := c + 1;
    d := 1;
    while d <= n do d := d * 2;
    n1 := n;
    e := 0;
    while n1 > 0 do
    begin
      if d <= n1 then
      begin
        n1 := n1 - d;
        e := e + 1;
      end;
      d := d div 2;
    end;
    if (n <= 0) or ((n = 1) and (p <> 0)) then
    begin
      write('-1');
      break;
    end
    else if e <= c then
    begin
      write(c);
      break;
    end;
  end;
end.