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