import java.util.*;

public class Mistura {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int n = sc.nextInt();
            int k = sc.nextInt();

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

            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }

            LinkedList<Integer> c = new LinkedList<>();
            long ans = 0;

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

                c.add(i);
                if (c.size() > k) {
                    c.removeFirst();
                }

                if (c.size() == k) {
                    ans += c.getFirst() + 1;
                }
            }

            System.out.println(ans);
        }

        sc.close();
    }
}
