#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
  cin >> n >> k;
  long long one = 1;
  long long res = 0;
  long long max_v = log2(n);
  if ((one << max_v) > n) max_v--;
  if (k == 1)
    cout << n;
  else {
    for (int i = max_v; i >= 0; i--) {
      res += one << (max_v - i);
    }
    cout << res;
  }
  return 0;
}
