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