#include <bits/stdc++.h>
using namespace std;
int a[10000000];
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
int main() {
  long long N;
  long long X;
  N = read();
  X = read();
  long long ans = 3 * X;
  long long L = X;
  long long B = X;
  int k = 1;
  while (L < (N - X)) {
    B = B / 2;
    k = k * 2;
    L = L + B;
    if (L <= (N - X)) {
      ans = ans + B * 3 * k;
    }
  }
  cout << ans << endl;
  return 0;
}
