#include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 60;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, x, ans;
  cin >> n >> x;
  ans = x + (n - x) * (x / (n - x) * 2 + 1);
  if (0 < n - x - 1) ans += (n - x - 1) * ((n - x) / (n - x - 1) + 1);
  if (0 < n - x - 2) ans += (n - x - 2) * ((n - x - 1) / (n - x - 2) + 1);
  cout << ans << endl;
}
