#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a, n--;
    else
      a = a * a, n /= 2;
  }
  return res;
}
void solve() {
  long long int n, k, i = 0, temp;
  cin >> n >> k;
  temp = n;
  vector<long long int> v;
  while (n > 0) {
    v.push_back(power(2, i));
    i++;
    n /= 2;
  }
  sort(v.begin(), v.end(), greater<long long int>());
  long long int si = v.size();
  if (k == 1)
    cout << temp;
  else {
    long long int ans = 0;
    for (long long int i = 0; i < si; i++) ans = ans ^ v[i];
    cout << ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
