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