#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;
        }
    }

    // Deliberately quadratic: for every left end, rescan from scratch
    // instead of reusing a two-pointer, so this is correct but O(N^2)
    // overall -- fine for N <= 5000, but should time out once N gets
    // close to 100000 (subtasks 3-6).
    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;
}
