#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, k, n, t1, t2;
  cin >> n >> k;
  long long ans = 2 * n + 1;
  t1 = (n - k);
  t2 = (k - 1);
  if (t1 < t2) {
    ans += 2 * t1 + t2;
  } else
    ans += 2 * t2 + t1;
  cout << ans << endl;
  return 0;
}
