#include <bits/stdc++.h>
using namespace std;
int main() {
  long long m, n, x = 1000000000000000000;
  cin >> m >> n;
  vector<long long> v, v1;
  long long p = 1;
  v.push_back(p);
  while (p <= x) {
    p *= 2;
    v.push_back(p);
  }
  int sz1 = v.size();
  for (long long i = 0; i < sz1 - 1; i++) {
    if (v[i] <= m) v1.push_back(v[i]);
  }
  long long sz = v1.size(), s = 0;
  for (long long i = sz - 1; i >= 0; i--) s += v1[i];
  if (n == 1)
    cout << m << endl;
  else
    cout << s << endl;
  return 0;
}
