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