#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long t = 0;
  while (n >= (1ll << t)) t++;
  long long tmp = (1ll << t) - 1;
  long long now = 0;
  if (k >= 2)
    cout << tmp << endl;
  else
    cout << n << endl;
}
