function PriorityQueue() {
    this.heap = [];
}

PriorityQueue.prototype = {
    push : function(x){
        var h = this.heap, i = h.length++, j;
        while(i){
            j = i-1 >> 1;
            if(h[j] <= x)break;
            h[i] = h[j];
            i = j;
        }
        h[i] = x;
    },
    pop : function(){
        var h = this.heap, r = h[0], x = h.pop();
        var i = 0, k = h.length >> 1, j;
        while (i < k) {
            j = (i << 1) + 1;
            if(h[j+1] < h[j])++j;
            if(x <= h[j])break;
            h[i] = h[j];
            i = j;
        }
        if(h.length)h[i] = x;
        return r;
    },
    size : function(){return this.heap.length;},
    top : function(){return this.heap[0];},
};



function Main(arg) {

  var N = arg.split("\n")[0].split(" ")[0]-0;
  var K = arg.split("\n")[0].split(" ")[1] - 0;
  var A = arg.split("\n")[1].split(" ").map(Number);

  var tmp = {};
  for (var i = 0; i < N; i++){
    if (tmp[A[i]] == undefined) {
      tmp[A[i]] = 0;
    }
    tmp[A[i]]++;
  }

  if (Object.keys(tmp).length <= K) {
    console.log(0);
    return;
  }

  var que = new PriorityQueue();
  Object.keys(tmp).forEach(function (key) {
    que.push(tmp[key]);
  });

  var min = 0;
  for (var i = 0; i < Object.keys(tmp).length-K; i++){
    min += que.pop();
  }

  console.log(min);

  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));