#include <bits/stdc++.h>
using namespace std;
using LL = long long;
char t[100];
int main() {
  LL n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << n;
    return 0;
  }
  LL n2 = n;
  LL z = 1;
  int il = 0;
  while (n2 != 0) {
    ++il;
    if (n2 % 2 == 0)
      t[il] = '0';
    else
      t[il] = '1';
    n2 /= 2;
  }
  bool czy = false;
  for (int i = il; i >= 1; --i) {
    if (t[i] == '1') czy = true;
    if (czy == true) {
      t[i] = '1';
    }
  }
  LL res = 0;
  LL p = 1;
  for (int i = 1; i <= il; ++i) {
    res += ((LL)t[i] - (LL)'0') * p;
    p *= 2;
  }
  cout << res;
}
