#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k, l, j, m, xx, i;
  cin >> n >> k;
  if (k == 1)
    cout << n;
  else {
    i = 1;
    xx = 1;
    while (i <= n) {
      xx *= 2;
      i *= 2;
    }
    cout << xx - 1;
  }
  return 0;
}
