////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE ////////// BEGIN TEMPLATE //////////
#define FILENAME "NotSoDiverse"

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

#ifndef LONG_LONG_MAX
#define LONG_LONG_MAX ~(1LL<<63)
#endif

#ifndef LONG_LONG_MIN
#define LONG_LONG_MIN -(~(1LL<<63))-1
#endif

#ifndef _DEBUG
bool __DEBUGGING__ = 0;
#else
bool __DEBUGGING__ = 1;
#endif

// to disable the definition of vsnprintf in <stdio.h> and/or <cstdio>
// to avoid compilation error when the function to_string is used
// #define __USE_MINGW_ANSI_STDIO 0

#define AREP(_, __, ___) for (__typeof(__) _ = (__) - ((__) > (___)); _ != (___) - ((__) > (___)); _ += 1 - (((__) > (___))>>1))
#define REPF(_, __, ___) for (__typeof(__) _ = (__); _ < (___); ++_)
#define REPB(_, __, ___) for (__typeof(__) _ = (__); _ > (___); --_)
#define REPFX(_, __, ___, ____) for (__typeof(__) _ = (__); _ < (___); _ += ____)
#define REPBX(_, __, ___, ____) for (__typeof(__) _ = (__); _ > (___); _ -= ____)
#define FORF(_, __, ___) for (__typeof(__) _ = (__); _ <= (___); ++_)
#define FORB(_, __, ___) for (__typeof(__) _ = (__); _ >= (___); --_)
#define FORFX(_, __, ___, ____) for (__typeof(__) _ = (__); _ <= (___); _ += ____)
#define FORBX(_, __, ___, ____) for (__typeof(__) _ = (__); _ >= (___); _ -= ____)
#define ALLF(_) _.begin(), _.end()
#define ALLB(_) _.rbegin(), _.rend()
#define ALLFC(_) _.cbegin(), _.cend()
#define ALLBC(_) _.crbegin(), _.crend()
#define ERROR(_...) { string __ = #_; replace(ALLF(__), ',', ' '); stringstream ___(__); istream_iterator<string> ____(___); err(____, _); }
#define lenof(_) (int)_.length()
#define szof(_) (int)_.size()
#define lenlof(_) (long)_.length()
#define szlof(_) (long)_.size()
#define lenllof(_) (long long)_.length()
#define szllof(_) (long long)_.size()
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define pf push_front
#define popf pop_front
#define mkp make_pair
#define mkt make_tuple
#define endl '\n'
#define as_s(_) #_
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef pair<ll, ll> pllll;
typedef vector<ll> vll;
typedef vector<pllll> vllll;

void redir_io() {
  #ifndef _DEBUG
  if (!freopen(FILENAME ".INP", "r", stdin)) cerr << "CANNOT OPEN " FILENAME ".INP [READING, STDIN]" << endl;
  if (!freopen(FILENAME ".OUT", "w", stdout)) cerr << "CANNOT OPEN " FILENAME ".OUT [WRITING, STDOUT]" << endl;
  #else
  #endif
};

void fast_io() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0); std::cout.tie(0);
};

template <typename T>
const bool maximize(T &a, const T &b) {
  if (b > a) a = b; else return false; return true;
};

template <typename T>
const bool maximize(T &a, initializer_list<const T> l) {
  return maximize(a, max(l));
};

template <typename T>
const bool minimize(T &a, const T &b) {
  if (b < a) a = b; else return false; return true;
};

template <typename T>
const bool minimize(T &a, initializer_list<const T> l) {
  return minimize(a, min(l));
};

template <typename T>
T sum() {
  return T();
};

template <typename T, typename... Args>
T sum(T a, Args... args) {
  return a + sum(args...);
};

template <typename T>
const T gcd(const T a, const T b) {
  return __gcd(a, b);
};

template <typename T>
const T lcm(const T a, const T b) {
  return a/gcd(a,b)*b;
};

const int clz(const unsigned int x) {
  return __builtin_clz(x);
};

const int ctz(const unsigned int x) {
  return __builtin_ctz(x);
};

const int clzl(const unsigned long x) {
  return __builtin_clzl(x);
};

const int ctzl(const unsigned long x) {
  return __builtin_ctzl(x);
};

const int clzll(const unsigned long long x) {
  return __builtin_clzll(x);
};

const int ctzll(const unsigned long long x) {
  return __builtin_ctzll(x);
};

const int popcount(const unsigned int x) {
  return __builtin_popcount(x);
};

const int popcountl(const unsigned long x) {
  return __builtin_popcountl(x);
};

const int popcountll(const unsigned long long x) {
  return __builtin_popcountll(x);
};

template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
#define arrsz(_) (sizeof(ArraySizeHelper(_)))

template <typename T>
string to_s(T value) {
  stringstream ss; ss << value; return ss.str();
};

void err(istream_iterator<string> it) {};

template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
};

template <typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> &pair_) {
  os << '{' << pair_.first << ';' << ' ' << pair_.second << '}';
  return os;
};

template <typename T>
void print_vec(const vector<T> &vec, const string separator = ", ", const bool brackets = true, const bool newline = true, ostream& os = cout) {
  if (brackets) os << '[';
  if (!vec.empty()) {
    copy(vec.begin(), vec.begin() + vec.size() - 1, ostream_iterator<T>(os, separator.c_str()));
    os << vec.back();
  };
  if (brackets) os << ']';
  if (newline) os << '\n';
};

template <typename T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  print_vec(vec, ", ", true, true, os);
  return os;
};

void print_as_binary(int mask, const int width = 0, const bool reversed = false, ostream& os = cout) {
  if (reversed) {
    queue<bool> q; while (mask) q.push(mask&1), mask >>= 1;
    while (szof(q) < width) q.push(0);
    while (!q.empty()) os << q.front(), q.pop();
  } else {
    stack<bool> st; while (mask) st.push(mask&1), mask >>= 1;
    while (szof(st) < width) st.push(0);
    while (!st.empty()) os << st.top(), st.pop();
  };
};
////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE ////////// END TEMPLATE //////////
///////// TEST CASES ///////// TEST CASES ///////// TEST CASES ///////// TEST CASES ///////// TEST CASES //////////
const int MAX_TEST_CASES = 1; int testcases = 1;

void pre_init() {

};

void get_test_cases() {
  if (MAX_TEST_CASES > 1) cin >> testcases;
};
///////// END TEST CASES ///////// END TEST CASES ///////// END TEST CASES ///////// END TEST CASES ///////// END TEST CASES /////////
//////// MAIN BODY //////// MAIN BODY //////// MAIN BODY //////// MAIN BODY //////// MAIN BODY ////////
// constraints
const int MAX_N = 2E5, MAX_K = 2E5, MAX_A = MAX_N;
// typedefs, structs, enums
// variables
int n, k;
vi a;

void get_input_data(const int testcase = -1) {
  cin >> n >> k; a.resize(n);
  REPF(i, 0, n) cin >> a[i];
};

array<int, MAX_A + 1> cnt;

void init(const int testcase = -1) {
  for (const int &x : a) ++cnt[x];
};

void solve(const int testcase = -1) {
  init(); vector<int> vec;
  FORF(i, 1, MAX_A) if (cnt[i]) vec.eb(i);
  sort(ALLF(vec), [](const int &num1, const int &num2) {return cnt[num1] < cnt[num2];});
  int res = 0, lim = szof(vec) - k;
  if (szof(vec) > k) REPF(i, 0, lim) res += cnt[vec[i]];
  cout << res;
};

void clear_data() {

};

// main function
int main(int argc, char **argv) {
  //redir_io();
  fast_io();
  pre_init(); get_test_cases();
  for (int testcase = 0; testcase != testcases; ++testcase) clear_data(), get_input_data(testcase), solve(testcase);
};

Measured memory_bytes: 2936