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