#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int main(void) {
  cout << std::fixed << std::setprecision(10);
  long long N, X, answer;
  cin >> N >> X;
  if (N % 2 == 0) {
    if (N / 2 >= X) {
      answer = (N - 1) * 3 - (X - 1) * 3;
    } else {
      answer = (N - 1) * 3 - (N - X - 1) * 3;
    }
  } else {
    answer = (N - 1) * 3;
  }
  cout << answer << endl;
  return 0;
}
