#include <bits/stdc++.h>
using namespace std;
int N, X, k;
int main() {
  cin >> N >> X;
  if (N % X == 0) {
    k = N / X;
    cout << (k - 1) * 3 * X << endl;
  } else {
    cout << (N - 1) * 3 << endl;
  }
  return 0;
}
