#include <iostream>
#include <vector>
using namespace std;

int main() {
    while (true) {
        int n, k;
        cin >> n >> k;

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

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

        vector<int> c;
        long long ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < c.size(); j++) {
                if (a[c[j]] == a[i]) {
                    c.erase(c.begin() + j);
                    break;
                }
            }

            c.push_back(i);
            if (c.size() > k) {
                c.erase(c.begin());
            }

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

        cout << ans << endl;
    }

    return 0;
}
