#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:500000000000")
void ending() { exit(0); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << n;
  } else {
    long long pow = 1;
    while (pow <= n) pow *= 2;
    cout << pow - 1;
  }
  ending();
  ;
}
