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