#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
long long int tri(long long int n)
{
return (n * (n + 1)) / 2;
}
int main()
{
int n, k;
cin >> n >> k;
int *a = new int[n];
for(int i = 0; i < n; i++)
cin >> a[i];
map<int, int> cn;
vector<map<int, int>> next;
next.resize(n);
for(int i = n - 1; i >= 0; i--)
{
next[i] = cn;
cn[a[i]] = i + 1;
}
vector<pair<int, int>> ranges, overlaps;
vector<int> ols;
for(int i = 0; i < n; i++)
{
int si = i;
if(i) for(; i < n && a[i-1] == a[i]; i++);
if(i == n)
break;
try:
if(si && next[i][a[i-1]] && next[i][a[i-1]] - 1 <= ranges.back().second)
continue;
catch:
;
set<int> nums;
int u = 0;
int j = i;
for(; j < n; j++)
{
if(!nums.count(a[j]))
{
nums.insert(a[j]);
u++;
if(u > k)
break;
}
}
if(ranges.empty() || ranges.back().second < j-1)
ranges.push_back(make_pair(i, j-1));
}
for(int i = 0; i < ranges.size(); i++)
{
//cout << "(" << ranges[i].first << ", " << ranges[i].second << "): ";
for(int j = 1; i + j < ranges.size(); j++)
{
if(ranges[i].second < ranges[i+j].first)
break;
//cout << "(" << ranges[i+j].first << ", " << ranges[i+j].second << "), ";
//overlaps.push_back(make_pair(ranges[i+j].first, ranges[i].second));
ols.push_back(ranges[i].second - ranges[i+j].first + 1);
}
//cout << endl;
}
/*for(pair<int, int> p : ranges)
cout << p.first << ", " << p.second << endl;
cout << endl;
for(int i = 0; i < ols.size(); i++)
cout << overlaps[i].first << ", " << overlaps[i].second << ", " << ols[i] << endl;*/
long long int ret = 0;
for(pair<int, int> p : ranges)
ret += tri(p.second - p.first + 1);
for(int i : ols)
ret -= tri(i);
cout << ret << endl;
}