#include <bits/stdc++.h>
using namespace std;
unsigned long long int pow1(int i) {
  unsigned long long int r = 1;
  while (i > 0) {
    r *= 2;
    i--;
  }
  return r;
}
int main() {
  unsigned long long int n, k, in, i = 0;
  cin >> n >> k;
  if (k == 1) {
    cout << n;
  } else {
    while (n > 0) {
      if (n % 2 == 1) {
        in = i;
      }
      n = n / 2;
      i++;
    }
    cout << pow1(in + 1) - 1;
  }
}
