#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  scanf("%I64d %I64d", &n, &k);
  if (k == 1)
    printf("%I64d\n", n);
  else {
    long long int r = 1;
    while (r <= n) r = r * 2;
    printf("%I64d\n", r - 1);
  }
  return 0;
}
