#include <bits/stdc++.h>
long long n, x, ans, last;
int main() {
  scanf("%lld%lld", &n, &x);
  ans += (n + x);
  if (fabs(double((n - 2 * x) / x) - (double)(n - 2 * x) / x) <= 1e-7) {
    ans += 2 * (n - 2 * x);
    printf("%lld\n", ans);
  } else {
    ans += (n - 2 * x) / x * 2 * x;
    last = n - 2 * x - (n - 2 * x) / x * x;
    ans += (x + x / last * 3 / 2);
    printf("%lld\n", ans);
  }
  return 0;
}
