// C: Not so Diverse
"use strict";

const DEBUG_MODE = false;
const rawInput = DEBUG_MODE
  ? "5 2\n1 1 2 2 5"
  : require("fs")
      .readFileSync("/dev/stdin", "utf8")
      .trim();

// memoize count of all occurrences in a map, taking note which is the top K max occurrences
// get sum of all occurrences that are not the top 2

const process = inputRaw => {
  const inputs = inputRaw.split("\n");
  const metadata = inputs[0].split(" ").map(item => parseInt(item));
  const N = metadata[0];
  const K = metadata[1];

  const integerList = inputs[1].split(" ").map(item => parseInt(item));

  const occurenceMap = integerList.reduce(
    (acc, item) =>
      Object.assign(acc, { [item]: acc[item] ? acc[item] + 1 : 1 }),
    {}
  );

  // sort decreasing
  const occurrences = Object.keys(occurenceMap)
    .reduce((acc, curr) => [...acc, occurenceMap[curr]], [])
    .sort((a, b) => b - a);

  let count = 0;

  // skip K occurrences and add the rest
  for (let i = occurrences.length - 1; i >= K; i--) {
    count += occurrences[i];
  }

  console.log(count);
};

process(rawInput);
