#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, j, k;
  cin >> n >> k;
  int i;
  int sum = 0;
  if (k == 1 || k == n) {
    cout << 3 * n;
  } else {
    cout << 3 + 2 * min(k - 1, n - k) + max(k - 1, n - k) + 2 * (n - 1);
  }
}
