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