#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (auto& x : a) cin >> x;

    // Every value is in [1, K] and all of them occur, so the K
    // smallest distinct values are exactly 1..K -- i.e. the target set
    // is the whole alphabet. No need to search for a threshold value;
    // a small counting array of size K is enough for the two pointers.
    vector<int> cnt(k + 1, 0);

    int l = 0, have = 0;
    ll ans = 0;

    for (int r = 0; r < n; r++) {
        if (cnt[a[r]]++ == 0) have++;

        while (have == k) {
            ans += n - r;

            if (--cnt[a[l]] == 0) have--;
            l++;
        }
    }

    cout << ans << '\n';

    return 0;
}
