#include <bits/stdc++.h>
using namespace std;
string tostr(int n) {
  stringstream rr;
  rr << n;
  return rr.str();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  cout << 4 * (min(k - 1, n - k)) + 3 * (max(k - 1, n - k)) + 3 << endl;
  return 0;
}
