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