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