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