#include <bits/stdc++.h>
using namespace std;
long long N;
long long X;
void solve() {
  long long sum;
  long long p;
  long long q;
  p = (N - X) / X;
  q = (N - X) % X;
  if (q == 0) {
    cout << 3 * p * X << endl;
    return;
  } else {
    long long r;
    r = X / q;
    sum = 3 * p * X + 3 * q * r;
    cout << sum << endl;
    return;
  }
}
int main() {
  cin >> N >> X;
  solve();
  return 0;
}
