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