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