#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 2e18;
const long long MAX = 405;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  string bin;
  long long num = n;
  while (num) {
    bin.push_back('0' + num % 2);
    num >>= 1;
  }
  if (k == 1) {
    cout << n;
    return 0;
  }
  long long l = bin.length();
  long long j = 2, ans = 1;
  while (l--) {
    ans *= 2;
  }
  cout << ans - 1;
  return 0;
}
