import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;
import std.math;
import std.functional;
import std.range;
import std.typecons;

void main(string[] args) {
  solve(readln, readln).writeln;
}

auto solve(string line1, string line2) {
  auto _ = line1.split.map!(to!int).array;
  auto N = _[0];
  auto K = _[1];
  auto a = line2.split;

  auto counter = new Counter!(string, int)(a);
  auto over = cast(int)counter.table.keys.length - K;
  if (over > 0) {
    return counter.items
      .sort!"a.value < b.value"
      .take(over)
      .map!"a.value"
      .sum;
  } else {
    return 0;
  }
}

unittest {
  assert(solve(
    "5 2",
    "1 1 2 2 5") == 1, "1");
  assert(solve(
    "4 4",
    "1 1 2 2") == 0, "2");
  assert(solve(
    "10 3",
    "5 1 3 2 4 1 1 2 3 4") == 3, "3");
}

class Counter(E, Int) {
  Int[E] table;

  this(E[] elems) {
    foreach(e; elems) {
      add(e);
    }
  }

  void add(E e, Int num = 1) {
    if (e in table) {
      table[e] += num;
    } else {
      table[e] = num;
    }
    if (table[e] == 0) {
      table.remove(e);
    }
  }

  Int get(E e) {
    return table.get(e, 0);
  }

  auto items() {
    return table.keys.map!(k => tuple!("key", "value")(k, table[k])).array;
  }
}