#include<iostream>
#include<unordered_set>
#include<unordered_map>
int main(){
std::ios_base::sync_with_stdio(0);std::cin.tie(NULL);
unsigned int n,k;
std::cin>>n>>k;
unsigned int d[500100];
unsigned int input;
std::unordered_set<unsigned int> s;
for(size_t i=0;i<n;i++){std::cin>>input;s.insert(input);d[i]=input;}
unsigned long long res=n;
for(size_t i=1;i<k;i++){res+=(n-i);}
if(n==k){std::cout<<res;return 0;}
if(s.size()==k){for(size_t i=k;i<n;i++){res+=(n-i);}std::cout<<res;return 0;}
if(n/2<k||n<100){
unsigned long long count=0;
std::unordered_map<unsigned int,unsigned int> map;
for(size_t i=0;i<n-k+1;i++){
count=1;
map.clear();
map[d[i]]++;
for(size_t j=1;j<n-i;j++){
if(!map[d[i+j]]){
count++;
map[d[i+j]]++;
}
if(count>k){break;}
if(k<j+1){
if(count<1+k){
res++;
}
}
}
}
}
else{
// only thing left
unsigned long long count=0;
std::unordered_map<unsigned int,unsigned int> map;
for(size_t i=0;i<n-k+1;i++){
count=1;
map.clear();
map[d[i]]++;
for(size_t j=1;j<n-i;j++){
if(!map[d[i+j]]){
count++;
map[d[i+j]]++;
}
if(count>k){break;}
if(k<j+1){
if(count<1+k){
res++;
}
}
}
}
}
}
std::cout<<res;
}