#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  scanf("%lld%lld", &n, &x);
  if (n == x * 2)
    printf("%lld\n", x * 3);
  else if (x * 2 > n)
    printf("%lld\n", 4 * (n - x) + x);
  else
    printf("%lld\n", 4 * (n - 2 * x) + x * 4);
}
