#include <stdio.h>

#define MAXN 100010

int main() {
    while (1) {
        int n, k;
        scanf("%d %d", &n, &k);

        if (n == 0 && k == 0) break;

        int a[MAXN];
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }

        int c[MAXN], c_size = 0;
        long long ans = 0;

        for (int i = 0; i < n; i++) {
            int j;
            for (j = 0; j < c_size; j++) {
                if (a[c[j]] == a[i]) {
                    for (int l = j; l < c_size - 1; l++) {
                        c[l] = c[l + 1];
                    }
                    c_size--;
                    break;
                }
            }

            c[c_size++] = i;
            if (c_size > k) {
                for (int l = 0; l < c_size - 1; l++) {
                    c[l] = c[l + 1];
                }
                c_size--;
            }

            if (c_size == k) {
                ans += c[0] + 1;
            }
        }

        printf("%lld\n", ans);
    }
    return 0;
}
