#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 == 1LL) {
    cout << n << endl;
  } else {
    long long tp = 1LL;
    while (tp <= n) {
      tp *= 2LL;
    }
    cout << tp - 1 << endl;
  }
  cin >> n;
}
