#include <iostream>
#include <vector>
#include <unordered_map>

int max_coins(const std::vector<int>& deck, int n, int k) {
    // Create a frequency map of card types
    std::unordered_map<int, int> card_count;
    for (int i = 0; i < n; i++) {
        card_count[deck[i]]++;
    }

    int coins = 0;
    
    // Create the initial hand with the first k cards
    std::unordered_map<int, int> hand;
    for (int i = 0; i < k; i++) {
        hand[deck[i]]++;
        card_count[deck[i]]--;
    }
    
    // Function to count pairs in the given map
    auto count_pairs = [](std::unordered_map<int, int>& map) {
        int pairs = 0;
        for (auto& entry : map) {
            pairs += entry.second / 2; // Count how many pairs can be made
        }
        return pairs;
    };

    coins += count_pairs(hand); // Start by counting pairs in the initial hand
    
    int deck_index = k; // Points to the next card in the deck
    while (deck_index < n) {
        // Two new cards are drawn from the deck
        hand[deck[deck_index]]++;
        hand[deck[deck_index + 1]]++;
        deck_index += 2; // Increment by two as two cards are drawn

        // Check for pairs in the hand
        coins += count_pairs(hand);

        // Remove pairs from the hand
        for (auto it = hand.begin(); it != hand.end();) {
            if (it->second >= 2) {
                it->second %= 2; // Keep only the remainder if there were pairs
            }
            if (it->second == 0) {
                it = hand.erase(it); // Remove card type from the hand if there are no cards left
            } else {
                it++;
            }
        }
    }

    return coins;
}

int main() {
    int n, k;
    std::cin >> n >> k;
    
    std::vector<int> deck(n);
    for (int i = 0; i < n; i++) {
        std::cin >> deck[i];
    }
    
    std::cout << max_coins(deck, n, k) << std::endl;
    return 0;
}
