#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n >> x;
  if (n % x == 0) {
    long long d = n / x;
    cout << x * (d - 1) * (long long)(3) << "\n";
  } else {
    cout << n * (long long)(3) - 3 << "\n";
  }
}
