#include<iostream>
#include<unordered_set>
#include<unordered_map>
#include<vector>
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];
for(size_t i=0;i<n;i++){std::cin>>d[i];}
unsigned long long res=n*k;
if(1<k) res-=((k)*(k-1))/2;
if(n==k){std::cout<<res;return 0;}
if(k<n/3)
std::unordered_map<unsigned int,unsigned int> map;
unsigned int size = k;
for(size_t i=0;i<k;i++){map[d[i]]++;}
for(size_t i=0;i<n-k;i++){
map[d[i+size]]++;
if(map[d[i]]<2){map.erase(d[i]);}
else{map[d[i]]--;}
}
for(size_t i=0;i<n;i++){d[i]++;}
std::cout<<res;
}