#include<iostream>
#include<sstream>
#include<deque>
#include<string>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
deque<long> arr;
long k;
long n;
//k = 3;
//n = 8;
//arr = {1, 2, 1, 1, 1, 3, 1, 4};
scanf("%ld",&n);
scanf("%ld",&k);
long temp;
for(int i=0;i<n;i++){
scanf("%ld",&temp);
arr.push_back(temp);
}
arr.resize(n);
deque<long> active_nums;
deque<long>::iterator it;
long subarrays = 0;
long index = 0;
long curr_num;
long num_to_remove;
long removed_index;
map<long, long> last_index;
if(set<long> (arr.begin(), arr.end()).size() <= k){
cout << arr.size()*(arr.size()+1)/2 << endl;
return;
}
while (index != arr.size()){
curr_num = arr[index];
it = find(active_nums.begin(), active_nums.end(), curr_num);
last_index[curr_num] = index;
if(it != active_nums.end()){
active_nums.erase(it);
active_nums.push_back(curr_num);
}else{
active_nums.push_back(curr_num);
if(active_nums.size() > k){
num_to_remove = active_nums.front();
//for(long x : active_nums) {num_to_remove = x; break;}
//cout << "For-loop: " << num_to_remove << endl;
active_nums.pop_front();
removed_index = last_index[num_to_remove];
//removed_index = arr.size() - (find(arr.rbegin() + arr.size() - index, arr.rend(), num_to_remove) - arr.rbegin()) - 1;
//cout << "Current: " << removed_index << endl << "Magic: " << last_index[num_to_remove] << endl;
subarrays += (removed_index*(2*index-removed_index-1)+2*index)/2;
arr.erase(arr.begin(), arr.begin()+removed_index+1);
last_index.clear();
index = 0;
}
}
index++;
}
subarrays += (arr.size()+1)*arr.size()/2;
cout << subarrays << endl;
}