#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6, mod = 1000000007;
long long n, m, x, k, d, p, z, sum;
vector<long long> v, ans;
set<long long> st;
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= 2 * n; i *= 2) v.push_back(i - 1);
  if (k == 1) {
    cout << n;
    return 0;
  } else {
    for (int i = v.size() - 1; i >= 0; i--) {
      if (i == 0 || (v[i] >= n && v[i - 1] < n)) {
        cout << v[i];
        return 0;
      }
    }
  }
  return 0;
}
