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