#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, k;
  cin >> n >> k;
  if (k == 1 || k == n) {
    cout << (3 * n);
  } else {
    cout << min(2 + 3 * (k - 1) + k + 3 + 3 * (n - k - 1),
                6 + 3 * (n - k - 1) + n - k + 3 * (k - 1));
  }
  return 0;
}
