#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
long long n, K;
long long dp[70][2];
int CNT(long long n) {
  int res = 0;
  while (n) {
    res++;
    n >>= 1;
  }
  return res;
}
long long C(long long d) {
  int S = CNT(n);
  int D = CNT(d);
  long long res = 0;
  for (int I = S; I >= D; I--) {
    memset(dp, 0, sizeof(dp));
    if (I == S)
      dp[0][0] = 1;
    else
      dp[0][1] = 1;
    for (int i = 0; i < (I); i++)
      for (int j = 0; j < (2); j++) {
        if (dp[i][j] == 0) continue;
        int lim = (j ? 1 : (n >> (I - i - 1) & 1));
        for (int k = 0; k <= lim; k++) {
          if (i < D) {
            if (i == D - 1 && d % 2 == 0)
              ;
            else {
              int w = d >> (D - i - 1) & 1;
              if (k != w) continue;
            }
          }
          if (i == 0 && !k) continue;
          dp[i + 1][j || k < lim] += dp[i][j];
        }
      }
    res += dp[I][0] + dp[I][1];
  }
  return res;
}
int main() {
  cin >> n >> K;
  long long ok = 0, ng = n / 2 + 1;
  while (ng - ok > 1) {
    long long t = (ng + ok) / 2;
    if (C(2 * t) >= K)
      ok = t;
    else
      ng = t;
  }
  long long ok2 = 0, ng2 = (n - 1) / 2 + 1;
  while (ng2 - ok2 > 1) {
    long long t = (ng2 + ok2) / 2;
    if (C(2 * t + 1) >= K)
      ok2 = t;
    else
      ng2 = t;
  }
  cout << max(ok * 2, ok2 * 2 + 1) << endl;
}
