#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  if (k == 1)
    cout << n;
  else {
    int bits = 0;
    while (n > 0) {
      n >>= 1;
      bits++;
    }
    cout << ((long long)1 << bits) - 1;
  }
  return 0;
}
