#include<iostream>
#include<set>
#include<map>
#include<vector>
using namespace std;

int main() {
	int n, x;
	cin >> n >> x;
	
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int end = 0;
	long long ans = 0;
	
	set<int> uniq;
	map<int, int> freq;
	for(int start = 0; start < n; start++) {
		while(uniq.size() <= x && end < n) {
			if(uniq.size() == x && freq[a[end]] == 0) {
				break;
			}
			uniq.insert(a[end]);
			freq[a[end]]++;
			end++;
		}
		ans += end - start;
		freq[a[start]]--;
		if(freq[a[start]] == 0) {
			uniq.erase(a[start]);
		}
	}
	cout << ans;
}
