#include <bits/stdc++.h>
using namespace std;
long long n, x, a, b, c;
double d;
int main() {
  cin >> n >> x;
  if (n == 2 * x) {
    cout << n / 2 * 3 << endl;
    return 0;
  }
  if ((n - x) % x == 0)
    cout << n + 2 * x * n - 2 * x * x - x << endl;
  else
    cout << n + 2 * x + 3 * (n - 2 * x) << endl;
}
