#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using pstr = pair<string, string>;
using vint = vector<int>;
using vstr = vector<string>;
int main() {
  int n, x;
  cin >> n >> x;
  if (n == 2 * x) {
    cout << 3 * x;
  } else {
    x = x > n / 2 ? n - x : x;
    int sum = n;
    int a = n - x;
    for (size_t i = n - x; i >= 1; i--) {
      while (a > 0) {
        int b = (a - x > 0) ? 2 : 1;
        sum += b * x;
        a -= x;
      }
    }
    cout << sum;
  }
  return 0;
}
