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

const int MAXA = 1000000;

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

    int N, K;
    cin >> N >> K;

    vector<int> a(N);
    vector<int> freq(MAXA + 1);

    for (int &x : a) {
        cin >> x;
        freq[x]++;
    }

    vector<bool> important(MAXA + 1, false);

    int found = 0;
    for (int x = 1; x <= MAXA && found < K; x++) {
        if (freq[x] > 0) {
            important[x] = true;
            found++;
        }
    }

    // timestamp, за да не чистим масив от 10^6 елемента
    vector<int> seen(MAXA + 1, 0);
    int timer = 0;

    long long ans = 0;

    for (int L = 0; L < N; L++) {
        timer++;
        int have = 0;

        for (int R = L; R < N; R++) {
            if (important[a[R]] && seen[a[R]] != timer) {
                seen[a[R]] = timer;
                have++;
            }

            if (have == K)
                ans++;
        }
    }

    cout << ans << '\n';
}
