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