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