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