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