#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main() {
  scanf("%lld%lld", &n, &m);
  if (m * 2 == n)
    printf("%lld\n", n / 2 * 3);
  else if (m * 2 > n)
    printf("%lld\n", m * 3);
  else
    printf("%lld\n", m * 3 + (n - m - n % m) * 3);
  return 0;
}
