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

    // Find the threshold value such that exactly K distinct values in
    // [1, threshold] occur in the array -- those are the K smallest.
    int threshold = 0, distinctSeen = 0;
    for (int v = 1; v <= MAXV && distinctSeen < k; v++) {
        if (present[v]) {
            distinctSeen++;
            threshold = v;
        }
    }

    vector<int> cnt(MAXV + 1, 0);
    int l = 0, have = 0;
    ll ans = 0;

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

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

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

    cout << ans << '\n';

    return 0;
}
