#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
long long a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long n, p;
  cin >> n >> p;
  long long ans = 1e18, res = 0;
  for (long long i = 1; i < N; i++) {
    long long t = n;
    t -= i * p;
    if (t < 0) continue;
    long long c = __builtin_popcount(t);
    if (!c) continue;
    if (i < c) continue;
    long long k = i * (p + 1);
    if (k > n) continue;
    if (max(c, i) < ans) {
      ans = max(c, i);
      res = i;
    }
  }
  if (ans > 1e16)
    cout << -1;
  else
    cout << res;
  return (0);
}
