#include <bits/stdc++.h>
using namespace std;
int const N = 1000005;
long double pi = 3.14159265359;
long long const mod = 1000000007;
void FAST() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void TXT() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  FAST();
  long long n, p;
  cin >> n >> p;
  for (long long j = 1; j <= 40; j++) {
    long long t = n - p * j;
    string s;
    while (t) {
      s += t % 2 + '0';
      t /= 2;
    }
    reverse(s.begin(), s.end());
    long long mx = 0, mn = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        mn++;
        long long p = 1;
        for (int k = 0; k < s.length() - i - 1; k++) p *= 2;
        mx += p;
      }
    }
    if (j >= mn && j <= mx) {
      cout << j;
      return (0);
    }
  }
  cout << -1;
}
