#include <bits/stdc++.h>
const double PI = 3.1415926535897932384626433832795028841971;
const int INF = 1000000007;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
long long n, d;
int main() {
  cin >> n >> d;
  long long ans;
  if (d == 1) {
    ans = n * (n - 1) / 2;
  } else if (d == 2) {
    ans = n * (n - 1) / 2 - 1;
  } else {
    ans = d + 2 * (n - 4) + (n - 4) * (n - 3) / 2;
  }
  cout << ans << endl;
}
