#include <bits/stdc++.h>
int main() {
  unsigned long long n, x, i, res = 0;
  scanf("%lld %lld", &n, &x);
  unsigned long long tmp = n / x;
  if (n % x == 0) {
    tmp--;
    res += (x * 3 * tmp);
    printf("%lld\n", res);
    return 0;
  }
  unsigned long long count = 0, tmp2 = n - x;
  i = 0;
  while (i <= tmp2) {
    if (i == 0) i += x;
    i++;
    count++;
  }
  res += (x * 3 * count);
  printf("%lld\n", res);
  return 0;
}
