#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long sad(long long n) {
  if (n == 0LL)
    return 1LL;
  else
    return sad(n >> 1LL) << 1LL;
}
int main(int argc, char const *argv[]) {
  while (cin >> n >> k) {
    if (k == 1LL)
      cout << n << endl;
    else
      cout << sad(n) - 1LL << endl;
  }
  return 0;
}
