#include <bits/stdc++.h>
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  unsigned long long cnt = 0;
  while (n > 1 && k > 0) {
    cnt += n + n - 3;
    n -= 2;
    --k;
  }
  printf("%llu", cnt);
  return 0;
}
