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

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

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

    const int MAXV = 1000000;

    vector<int> a(n);
    vector<int> present(MAXV + 1, 0);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        present[a[i]] = 1;
    }

    int limit = 0;
    int found = 0;

    for (int x = 1; x <= MAXV; x++) {
        if (present[x]) {
            found++;

            if (found == k) {
                limit = x;
                break;
            }
        }
    }

    vector<int> cnt(MAXV + 1, 0);

    int l = 0;
    int have = 0;
    long long ans = 0;

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

            cnt[a[r]]++;
        }

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

            if (a[l] <= limit) {
                cnt[a[l]]--;

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

            l++;
        }
    }

    cout << ans << '\n';

    return 0;
}
