#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
int k;
vector<unsigned long long> a;
int main() {
  cin >> n >> k;
  if (k == 1) {
    cout << n << endl;
    return 0;
  }
  for (unsigned long long i = 1; i < 1e18; i *= 2) a.push_back(i);
  a.push_back(a[a.size() - 1] * 2);
  int pos = 0;
  for (int i = 1; i < a.size(); i++) {
    if (a[i] > n) {
      pos = i - 1;
      break;
    }
  }
  unsigned long long ans = a[pos] ^ (a[pos] - 1);
  cout << ans << endl;
  return 0;
}
