#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, ans = 1;
  cin >> n >> k;
  if (k == 1)
    cout << n;
  else {
    while (n) n /= 2, ans *= 2;
    cout << ans - 1;
  }
}
