#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, b, a;
  cin >> n >> k;
  b = k;
  a = n;
  long long x = 1, y, z, ans;
  while (k > (pow(2, x + 1) - 2)) x++;
  k = k - pow(2, x) + 1;
  z = pow(2, x);
  k = k % z;
  z = pow(2, x - 1);
  ans = n - k;
  ans = ans / z;
  if (ans % 2 == 0)
    cout << ans << "\n";
  else {
    x = 0;
    k = b;
    while (k > (pow(2, x + 1) - 1)) x++;
    x++;
    k = k - pow(2, x - 1);
    n = a - k;
    long long ans1 = n / pow(2, x - 1);
    if (ans1 == ans)
      cout << ans << "\n";
    else
      cout << ans - 1 << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
