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

using ll = long long;

const int MAXV = 1000000;

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

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

    vector<int> a(n);
    vector<char> present(MAXV + 1, 0);
    for (auto& x : a) {
        cin >> x;
        present[x] = 1;
    }

    int threshold = 0, distinctSeen = 0;
    for (int v = 1; v <= MAXV && distinctSeen < k; v++) {
        if (present[v]) {
            distinctSeen++;
            threshold = v;
        }
    }

    // N <= 5000, so for every left end l we can find, independently,
    // the smallest right end r for which [l, r] contains every target,
    // without the two-pointer trick that keeps l monotone. A counting
    // array indexed directly by value (touched cells reset afterwards)
    // avoids any hashing overhead.
    vector<int> cnt(MAXV + 1, 0);

    ll ans = 0;
    for (int l = 0; l < n; l++) {
        int have = 0;
        int r = l;

        for (; r < n; r++) {
            if (a[r] <= threshold && cnt[a[r]]++ == 0) have++;
            if (have == k) {
                ans += n - r;
                break;
            }
        }

        for (int i = l; i <= r && i < n; i++) {
            if (a[i] <= threshold) cnt[a[i]] = 0;
        }
    }

    cout << ans << '\n';

    return 0;
}
