#include <bits/stdc++.h>
using namespace std;
const long long inf = 9.2e18;
const int maxn = 2e5 + 70;
const int INF = 2.1e9;
const int maxm = 1e6 + 70;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
long long n, m, k;
int a[maxn];
int main() {
  while (cin >> n >> k) {
    long long ans;
    if (k == 1) {
      ans = n;
    } else {
      int t = 0;
      while (n) {
        t++;
        n >>= 1;
      }
      ans = ((long long)1 << t) - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
