#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  long long s = 3LL * (n - 1LL);
  if (n % 2 == 0)
    if (x > n / 2)
      s -= 3LL * (n - x - 1);
    else
      s -= 3LL * (x - 1);
  cout << s;
}
