#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t = 1, n, k, p, lop, s, no;
  while (t--) {
    scanf("%lld %lld", &n, &k);
    s = k - 1;
    p = 2;
    p = p + (s * 3);
    p++;
    if (n > k) {
      p = p + k;
      lop = n - k - 1;
      if (lop == 0)
        p = p + 2;
      else if (lop > 0) {
        p = p + (lop * 3);
        p = p + 2;
      }
    }
    no = p;
    p = 0;
    s = n - k;
    p = 2;
    if (s == 1) {
      p = p + 3;
    } else if (s > 0) {
      p = p + ((s - 1) * 3);
      p = p + 3;
    }
    p++;
    if (k > 1) {
      p = p + n - k + 1;
      lop = k - 1;
      if (lop == 1)
        p = p + 2;
      else if (lop > 0) {
        p = p + ((lop - 1) * 3);
        p = p + 2;
      }
    }
    if (no < p) p = no;
    printf("%lld\n", p);
  }
  return 0;
}
