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