#include <bits/stdc++.h>
using namespace std;
long long high(long long n) {
  long long cnt = 0;
  while (n != 0) {
    n = (n >> 1);
    cnt++;
  }
  return cnt;
}
int main(int argc, char const *argv[]) {
  long long t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    if (k == 1)
      cout << n << endl;
    else {
      long long x = high(n);
      x = pow(2, x) - 1;
      cout << x << endl;
    }
  }
  return 0;
}
