#include <bits/stdc++.h>
using namespace std;
const double inf = 0x3f3f3f3f;
const double eps = 1e-8;
int shu[100];
int main() {
  memset(shu, 0, sizeof shu);
  for (int i = 0; i < 99; i++) {
    shu[i] = i;
  }
  int n, k, ans = 0;
  cin >> n >> k;
  if (k == 1 || k == n) {
    ans = 6 + (n - 2) * 3 + shu[0];
  } else if (k <= n / 2 + shu[0] && k >= 2) {
    ans = 3 + n + k + shu[0] + (n - 2) * 2;
  } else {
    ans = 6 + (n - (k + 1)) + (n - 1) + (n - 2) * 2 + shu[0];
  }
  cout << ans << endl;
  return 0;
}
