#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, ans = 0, l = 1;
  scanf("%I64d%I64d", &n, &m);
  while (l * 2 <= n) l = l * 2;
  if (m == 1)
    printf("%I64d\n", n);
  else
    printf("%I64d\n", l * 2 - 1);
  return 0;
}
