#include <bits/stdc++.h>
using namespace std;
const int INF = (INT_MAX / 2);
const double eps = 1e-14;
const double PI = M_PI;
int main() {
  long long N, X;
  cin >> N >> X;
  long long ans = 3 * X + (N % X) * 3 * X;
  cout << ans << endl;
  return 0;
}
