#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 233;
inline int get(int u) {
  int ret = 0;
  while (u > 0) {
    if (u & 1) ret++;
    u >>= 1;
  }
  return ret;
}
int main() {
  int n, p;
  while (scanf("%d%d", &n, &p) != EOF) {
    int t = n;
    int ans = -1;
    for (int i = 1; i <= 100; i++) {
      t = n - i * p;
      if (t <= 0) break;
      if (i >= get(t) && i <= t) {
        ans = i;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
