#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
  while (cin >> n >> k) {
    if (k == 1) {
      cout << n << endl;
      continue;
    }
    int cnt = 0;
    while (n > 0) {
      ++cnt;
      n >>= 1;
    }
    long long res = 1;
    cout << ((res << cnt) - 1) << endl;
  }
  return 0;
}
