#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 20;
int n = 0, k = 0, a[maxn], g = 0;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    a[i] = 1;
  }
  if (k == 1 || k == n) {
    a[1] = 2;
    a[0] = 0;
    g = 3;
    for (int i = 1; i < n; i++) {
      g += a[i] + 2;
    }
    cout << g - 1;
  } else {
    k -= 1;
    if (n - 1 - k > k) {
      a[k - 1] = 2;
      a[k] = 0;
      g = 3;
      for (int i = k - 1; i >= 0; i--) {
        g += a[i] + 2;
      }
      g += k + 1;
      for (int i = k + 1; i < n; i++) {
        g += a[i] + 2;
      }
      cout << g - 2;
    } else {
      a[k + 1] = 2;
      a[k] = 0;
      g = 3;
      for (int i = k + 1; i < n; i++) {
        g += a[i] + 2;
      }
      g += n - 1 - k;
      for (int i = k - 1; i >= 0; i--) {
        g += a[i] + 2;
      }
      cout << g - 1;
    }
  }
  return 0;
}
