#include <bits/stdc++.h>
using namespace std;
long long xorsum(long long n, long long k) {
  if (k == 1) return n;
  int msb = (int)log2((double)n);
  if ((1ll << msb) > n) msb--;
  return (2ll << msb) - 1;
}
int main() {
  long long n, k;
  cin >> n >> k;
  cout << xorsum(n, k) << endl;
  return 0;
}
