#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000;
int main() {
  int n, k;
  cin >> n >> k;
  if (k == 1 || n == k) {
    cout << n * 3 << endl;
  } else {
    int a = (n - k + 1) * 3 + (k - 1) * 3 + (n - k);
    int b = k * 3 + (n - k) * 3 + k - 1;
    cout << min(a, b) << endl;
  }
}
