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