import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // size of the array
        int k = scanner.nextInt(); // maximum distinct elements allowed
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            b[i] = scanner.nextInt(); // input array elements
        }

        int count = 0; // to count valid subarrays
        Map<Integer, Integer> g = new HashMap<>(); // hashmap to store frequency of elements

        for (int i = 0, j = 0; j < n; j++) {
            // Add new elements on the right
            g.put(b[j], g.getOrDefault(b[j], 0) + 1);

            // While the size of the hashmap exceeds k, shrink from the left
            while (g.size() > k) {
                g.put(b[i], g.get(b[i]) - 1);
                if (g.get(b[i]) == 0) {
                    g.remove(b[i]);
                }
                i++;
            }

            // Count subarrays ending at j
            count += (j - i + 1); // All subarrays from i to j are valid
        }

        System.out.println(count); // Output the count of valid subarrays
    }
}
