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