#include <bits/stdc++.h>
using namespace std;
long long nextPow(long long n) {
  while (n & (n - 1)) {
    n = n & (n - 1);
  }
  return n << 1;
}
int main() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  if (k == 1) {
    cout << n << "\n";
    exit(0);
  }
  long long res = nextPow(n) - 1;
  cout << res << "\n";
}
