#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
long long ans = 0;
int r = -1;
map<int, int> cnt;
for (int l = 0; l < n; l++)
{
while (r < n && cnt.size() < k)
{
r++;
if (r == n)
break;
cnt[a[r]]++;
}
ans += n - r;
cnt[a[l]]--;
if (cnt[a[l]] == 0)
cnt.erase(a[l]);
}
cout << ans << '\n';
return 0;
}