#include <bits/stdc++.h>
#define Fname "seq"
using namespace std;
const int MaxN = 3e5 + 7;
const long long INF = 1e14;
long long h, a[MaxN], n, cur;
unsigned long long d[MaxN], res = INF, k;
bool sol;
int main () {
// freopen (Fname".in", "r", stdin);
// freopen (Fname".out", "w", stdout);
scanf ("%d%d", &n, &h);
for (int i = 1; i <= n; ++ i)
a[i] = (i < h) ? 0 : i - h, d[i] = a[i] + d[i - 1];
// scanf ("%d", a + i), d[i] = a[i] + d[i - 1];
k = (h * (h + 1)) / 2;
for (int i = 1; i <= n - h + 1; ++ i)
{
if (a[i] <= 1 && k - (d[i + h - 1] - d[i - 1]) < res)
{
sol = true;
for (int j = i + 1; j < i + h; ++ j) {
if (a[j] > j - (i + 1) + 2) {
sol = false;
i = j;
break;
}
}
if (sol)
res = k - (d[i + h - 1] - d[i - 1]);
}
}
if (res == INF)
puts ("-1");
else
printf ("%I64d", res);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgRm5hbWUgInNlcSIKICAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAKY29uc3QgaW50IE1heE4gPSAzZTUgKyA3Owpjb25zdCBsb25nIGxvbmcgSU5GID0gMWUxNDsKICAKbG9uZyBsb25nIGgsIGFbTWF4Tl0sIG4sIGN1cjsKdW5zaWduZWQgbG9uZyBsb25nIGRbTWF4Tl0sIHJlcyA9IElORiwgazsKYm9vbCBzb2w7CmludCBtYWluICgpIHsKLy8gIGZyZW9wZW4gKEZuYW1lIi5pbiIsICJyIiwgc3RkaW4pOwovLyAgZnJlb3BlbiAoRm5hbWUiLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIHNjYW5mICgiJWQlZCIsICZuLCAmaCk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArKyBpKQogICAgICAgIGFbaV0gPSAoaSA8IGgpID8gMCA6IGkgLSBoLCBkW2ldID0gYVtpXSArIGRbaSAtIDFdOwovLyAgICAgIHNjYW5mICgiJWQiLCBhICsgaSksIGRbaV0gPSBhW2ldICsgZFtpIC0gMV07CiAgICBrID0gKGggKiAoaCArIDEpKSAvIDI7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuIC0gaCArIDE7ICsrIGkpCiAgICB7CiAgICAgICAgaWYgKGFbaV0gPD0gMSAmJiBrIC0gKGRbaSArIGggLSAxXSAtIGRbaSAtIDFdKSA8IHJlcykKICAgICAgICB7CiAgICAgICAgICAgIHNvbCA9IHRydWU7CiAgICAgICAgICAgIGZvciAoaW50IGogPSBpICsgMTsgaiA8IGkgKyBoOyArKyBqKSB7CiAgICAgICAgICAgICAgICBpZiAoYVtqXSA+IGogLSAoaSArIDEpICsgMikgewogICAgICAgICAgICAgICAgICAgIHNvbCA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgIGkgPSBqOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzb2wpCiAgICAgICAgICAgICAgICByZXMgPSBrIC0gKGRbaSArIGggLSAxXSAtIGRbaSAtIDFdKTsKICAgICAgICB9CiAgICB9CiAgICBpZiAocmVzID09IElORikKICAgICAgICBwdXRzICgiLTEiKTsKICAgIGVsc2UKICAgICAgICBwcmludGYgKCIlSTY0ZCIsIHJlcyk7CiAgICByZXR1cm4gMDsKfQ==