#include <bits/stdc++.h>
using namespace std;
long long n, x, t;
int32_t main() {
  scanf("%lld %lld", &n, &x);
  t = 3 * (n - 1);
  if (n & 1) return !printf("%lld", t);
  printf("%lld", t - 3 * (min(x, n - x) - 1));
}
