#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 2 && n == 2) {
    cout << 6;
    return 0;
  }
  if (k == 1 || k == n) {
    cout << 6 + (n - 2) * 3;
    return 0;
  }
  cout << 6 + min(k - 1 - 1, n - k - 1) + (n - 1) + (n - 2) * 2;
}
