#include <bits/stdc++.h>
using namespace std;
template <typename P, typename Q>
ostream& operator<<(ostream& os, pair<P, Q> p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
int main(int argc, char* argv[]) {
  long long int n, x;
  while (cin >> n >> x) {
    long long int sum = 0;
    sum += 3 * x * ((n - x) / x);
    long long int y = ((n - x) % x);
    sum += 3 * y * (x / y);
    cout << sum << endl;
  }
  return 0;
}
