#include <bits/stdc++.h>
using namespace std;
long long xorsum(long long n, long long k) {
  if (k == 1) return n;
  int msb = (long long)log2((double)n);
  if (k <= msb + 1) return (2ll << msb) - 1;
  long long mark[] = {n, 1ll, n + 1, 0ll};
  long long ans = mark[n % 4ll];
  k = n - k;
  if (k) {
    if (ans == 0ll || ans == 1ll)
      ans ^= xorsum(n, k);
    else {
    }
  }
  return ans;
}
long long solve(long long n, long long k) {
  if (k == 1) return n;
  long long res = 1ll;
  while (res <= n) {
    res <<= 1;
  }
  return res - 1;
}
int main() {
  long long n, k;
  cin >> n >> k;
  cout << solve(n, k) << endl;
  return 0;
}
