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