#include <bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1000000007;
const double PI = acos(-1.0);
template <typename T>
inline T read(T &x) {
  x = 0;
  int _f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') _f |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x = _f ? -x : x;
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
long long n, k;
int main() {
  read(n), read(k);
  long long res = 1LL;
  int cnt = 0;
  while (res <= n) {
    cnt++;
    res <<= 1LL;
  }
  res >>= 1LL;
  if (k == 1)
    cout << n << endl;
  else
    cout << (res ^ (res - 1LL)) << endl;
  return 0;
}
