#include <bits/stdc++.h>
using namespace std;
const long long LLINF = (1LL << 60);
const long long INF = (1LL << 30);
const long long MOD = 1000000007;
long long N, X;
signed main() {
  cin >> N >> X;
  long long a = min(X, N - X);
  long long b = max(X, N - X);
  if (a == b) {
    printf("%lld\n", 3 * a);
    return 0;
  } else if (2 * a == b) {
    printf("%lld\n", 6 * a);
    return 0;
  }
  if (N % 2 == 0) {
    printf("%lld\n", (long long)(3) * b);
  } else {
    printf("%lld\n", (long long)(3) * (N - 1));
  }
  return 0;
}
