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