#include<iostream>
#include<set>
#include<map>
#include<vector>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
int end = 0;
long long ans = 0;
set<int> uniq;
map<int, int> freq;
for(int start = 0; start < n; start++) {
while(uniq.size() <= x && end < n) {
if(uniq.size() == x && freq[a[end]] == 0) {
break;
}
uniq.insert(a[end]);
freq[a[end]]++;
end++;
}
ans += end - start;
freq[a[start]]--;
if(freq[a[start]] == 0) {
uniq.erase(a[start]);
}
}
cout << ans;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHNldD4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTx2ZWN0b3I+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLCB4OwoJY2luID4+IG4gPj4geDsKCQoJdmVjdG9yPGludD4gYShuKTsKCWZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGNpbiA+PiBhW2ldOwoJCglpbnQgZW5kID0gMDsKCWxvbmcgbG9uZyBhbnMgPSAwOwoJCglzZXQ8aW50PiB1bmlxOwoJbWFwPGludCwgaW50PiBmcmVxOwoJZm9yKGludCBzdGFydCA9IDA7IHN0YXJ0IDwgbjsgc3RhcnQrKykgewoJCXdoaWxlKHVuaXEuc2l6ZSgpIDw9IHggJiYgZW5kIDwgbikgewoJCQlpZih1bmlxLnNpemUoKSA9PSB4ICYmIGZyZXFbYVtlbmRdXSA9PSAwKSB7CgkJCQlicmVhazsKCQkJfQoJCQl1bmlxLmluc2VydChhW2VuZF0pOwoJCQlmcmVxW2FbZW5kXV0rKzsKCQkJZW5kKys7CgkJfQoJCWFucyArPSBlbmQgLSBzdGFydDsKCQlmcmVxW2Fbc3RhcnRdXS0tOwoJCWlmKGZyZXFbYVtzdGFydF1dID09IDApIHsKCQkJdW5pcS5lcmFzZShhW3N0YXJ0XSk7CgkJfQoJfQoJY291dCA8PCBhbnM7Cn0K