#include <bits/stdc++.h>
using namespace std;
const int m = 1000000007;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, k;
  cin >> n;
  cin >> k;
  if (n == 2) {
    cout << "6" << endl;
  } else {
    int ans = n + 2 + 2 * (n - 1) + min((k - 1), (n - k));
    cout << ans << endl;
  }
  return 0;
}
