/*
*/
#include<bits/stdc++.h>
using namespace std;
#define maxn 300010
#define ll long long
map<int,int> M;
int a[maxn];
int cal(ll x)
{
int cnt=0;
while(x)
{
cnt+=(x%2);
x/=2;
}
return cnt;
}
int main()
{
ios::sync_with_stdio(false);
// cout<<((1ll<<30)-1)<<" "<<1000000000+1000*30;
ll n,p;cin>>n>>p;
int i;
for(i=1;i<=30;i++)
{
ll N=n-i*p;
int k=cal(N);
if(k>i||i>N) continue;
//当i>=30时,k一定是<=i的(i可以的表示范围为[i,2^i-1],N不会超过2^30-1,其实不止这些),所以第一个条件一定成立
//如果当答案==31,说明i==30不符合条件,即N<30;并且i==31时,k<=i,即N>=31;条件矛盾
//综上i>=31一定不会构成解
cout<<i<<endl;break;
}
if(i==31) cout<<-1;
return 0;
}