#include <bits/stdc++.h>
using namespace std;
long long int n, k;
int main() {
  cin >> n >> k;
  if (n == k) {
    puts("1");
    return 0;
  }
  if (k == 1) {
    printf("%lld\n", n);
    return 0;
  }
  if (((k + 1) & k) == 0) {
    if (n % (k + 1) == k) {
      cout << 2ll * ((n - k) / (k + 1)) + 1 << endl;
    } else
      cout << 2ll * (n / (k + 1)) << endl;
  } else {
    long long int t = 1;
    while ((1ll << t) <= k) t++;
    t--;
    cout << (1 + (n - k - 1) / (1ll << t)) * 2 << endl;
  }
  return 0;
}
