#include <bits/stdc++.h>
using namespace std;
long long n, k, v[500001], ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  if (k <= n / 2) {
    long long q = k;
    while (q >= 1) {
      q--;
      ans += 3;
    }
    ans += k - 1;
    for (int i = k + 1; i <= n; i++) ans += 3;
    cout << ans;
  } else {
    long long q = k;
    while (q <= n) {
      q++;
      ans += 3;
    }
    ans += n - k;
    for (int i = k - 1; i >= 1; i--) ans += 3;
    cout << ans;
  }
  return 0;
}
