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