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