#include <bits/stdc++.h>
using namespace std;
double tick() {
  static clock_t oldt, newt = clock();
  double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
const long long linf = 1e18;
const int inf = 1e9;
int main() {
  int n, pos;
  cin >> n >> pos;
  if (n == pos) {
    return cout << n * 3 << "\n", 0;
  }
  cout << (n * 3) + min(pos - 1, n - pos) << "\n";
  return 0;
}
