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