Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

-----Constraints-----
 - 1 \leq K \leq N \leq 200000
 - 1 \leq A_i \leq N
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 ... A_N

-----Output-----
Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

-----Sample Input-----
5 2
1 1 2 2 5

-----Sample Output-----
1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Source: atcoder | Difficulty: EASY


Solutions:
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import Counter
dic = Counter(a)
dic = sorted(list(dic.items()), key=lambda x: x[1])
ans = 0
cnt = 0
l = max(len(dic) - k, 0)
for i in dic:
	if cnt == l:
		break
	ans = ans + i[1]
	cnt = cnt + 1
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
import collections
cA = collections.Counter(A)
sorted_ls = sorted(list(cA.values()))
sum_ls = sum(sorted_ls)
if len(sorted_ls) > K:
	print(sum(sorted_ls[:len(sorted_ls) - K]))
else:
	print(0)


import collections as c
(n, k) = map(int, input().split())
a = c.Counter(map(int, input().split()))
print([0, sum(sorted([*a.values()])[:len(a) - k])][len(a) > k])


from collections import Counter
(n, k) = list(map(int, input().split()))
ctr = Counter(list(map(int, input().split())))
aa = sorted(list(ctr.items()), key=lambda x: x[1])
if len(aa) <= k:
	print(0)
else:
	print(sum([x[1] for x in aa[:len(aa) - k]]))


from collections import Counter
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
num = Counter(s)
if len(num) <= k:
	print(0)
else:
	cnt = len(num) - k
	ans = 0
	i = 0
	for v in sorted(num.values()):
		if cnt == i:
			break
		ans += v
		i += 1
	print(ans)


import collections
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
(values, counts) = zip(*collections.Counter(A).most_common())
ans = 0
B = counts[K:]
for i in B:
	ans += i
print(ans)


from collections import Counter, deque
(_, k) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
d = deque(sorted(Counter(a).values()))
while k < len(d):
	ans += d.popleft()
else:
	print(ans)


import collections
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
i = 0
cnt = 0
for (key, val) in sorted(c.items(), key=lambda x: -x[1]):
	cnt += val
	i += 1
	if i >= k:
		break
print(n - cnt)


import operator
(n, k) = [int(_) for _ in input().split()]
D = dict()
A = [int(_) for _ in input().split()]
for _ in range(n):
	if A[_] in D:
		D[A[_]] += 1
	else:
		D[A[_]] = 1
D = dict(sorted(list(D.items()), key=operator.itemgetter(1), reverse=True))
c = 0
i = 0
for _ in D:
	if i >= k:
		c += D[_]
	i += 1
print(c)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
dic = {}
for a in A:
	if a in dic.keys():
		dic[a] += 1
	else:
		dic[a] = 1
dic = sorted(dic.items(), key=lambda x: x[1], reverse=True)
ans = 0
for (i, j) in dic[K:]:
	ans += j
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
freq = [0] * (n + 1)
for i in l:
	freq[i] += 1
freq.sort()
vf = len(freq) - k if len(freq) > k else 0
print(sum(freq[:vf]))


from collections import Counter
(N, K) = map(int, input().split())
A = Counter(input().split())
print(sum(sorted(A.values(), reverse=True)[K:]))


from collections import Counter
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A = Counter(A).most_common()
s = 0
for i in range(min(K, len(A))):
	s += A[i][1]
print(N - s)


(N, K) = map(int, input().split())
A = {}
for i in input().split():
	A[i] = A.get(i, 0) + 1
A = sorted(A.values())
print(sum(A[0:len(A) - K]))


(n, k) = list(map(int, input().split()))
an = [int(num) for num in input().split()]
kind = {}
for a in an:
	if not a in kind:
		kind[a] = 1
	else:
		kind[a] += 1
sortedKind = sorted(list(kind.items()), key=lambda x: x[1])
if len(sortedKind) > k:
	count = 0
	for check in sortedKind[:len(sortedKind) - k]:
		count += check[1]
	print(count)
else:
	print(0)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
import collections
a = collections.Counter(a)
key = list(a.values())
key.sort()
ans = sum(key[:len(key) - k])
print(ans)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for a in A:
	d[a] = d.get(a, 0) + 1
if len(d) <= k:
	print(0)
else:
	d = sorted(d.values())
	cnt = 0
	for i in range(len(d) - k):
		cnt += d[i]
	print(cnt)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
freq = [0] * (n + 1)
for i in l:
	freq[i] += 1
freq.sort()
print(sum(freq[:n - k + 1]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import Counter
ac = sorted(list(Counter(a).values()))
le = len(ac)
if le <= k:
	print(0)
else:
	count = 0
	for i in range(le - k):
		count += ac[i]
	print(count)


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
a_dict = {}
for i in range(N):
	if a[i] not in a_dict.keys():
		a_dict[a[i]] = 1
	else:
		a_dict[a[i]] += 1
ans = 0
if len(a_dict) <= K:
	print(ans)
else:
	sort_a_dict_list = sorted(a_dict.items(), key=lambda x: x[1])
	for j in range(len(a_dict) - K):
		ans += sort_a_dict_list[j][1]
	print(ans)


nk = list(map(int, input().split()))
(n, k) = (nk[0], nk[1])
balls = {}
for ball in list(map(int, input().split())):
	if ball in balls:
		balls[ball] += 1
	else:
		balls[ball] = 1
size = len(list(balls.keys()))
swap_balls = list([(x[1], x[0]) for x in list(balls.items())])
swap_balls.sort()
count = 0
for (ball_count, ball_number) in swap_balls:
	if size <= k:
		break
	else:
		count += ball_count
		size -= 1
print(count)


(N, K) = input().split()
A = dict()
for i in input().split():
	if int(i) in A:
		A[int(i)] += 1
	else:
		A[int(i)] = 1
hoge = []
for i in A.values():
	hoge.append(i)
hoge.sort()
sum = 0
changed = 0
while len(hoge) - changed > int(K):
	sum += hoge[changed]
	changed += 1
print(sum)


from collections import Counter
(a, b) = map(int, input().split())
c = Counter(list(map(int, input().split())))
cnt = 0
l = []
m = []
for (x, y) in c.items():
	l += [y]
	m += [x]
M = len(m)
L = sorted(l)
if M <= b:
	print(0)
if M > b:
	for i in range(M - b):
		cnt += L[i]
	print(cnt)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
dic = {}
for i in A:
	if i not in list(dic.keys()):
		dic[i] = 1
	else:
		dic[i] += 1
dic = sorted(list(dic.items()), key=lambda x: x[1], reverse=True)
k = 0
ans = 0
for (key, value) in dic:
	if k >= K:
		ans += value
	k += 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
	if a[i] not in num_map:
		num_map[a[i]] = 1
	else:
		num_map[a[i]] += 1
rest_key_num = max(0, len(num_map) - k)
values = sorted(list(num_map.values()))
res = 0
for j in range(rest_key_num):
	res += values[j]
print(res)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
D = dict.fromkeys(range(1, n + 1), 0)
ans = 0
for a in A:
	D[a] += 1
D = sorted(D.items(), key=lambda x: x[1])
for i in range(n - k):
	ans += D[i][1]
print(ans)


import collections
(N, K) = map(int, input().split())
lsA = list(map(int, input().split()))
counterA = collections.Counter(lsA)
valu = list(counterA.values())
valu.sort()
kind = len(set(lsA))
if kind <= K:
	ans = 0
else:
	ans = sum(valu[:kind - K])
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
dic = {}
for i in range(N + 1):
	dic[i] = 0
for i in A:
	dic[i] += 1
dic_sort = sorted(dic.values(), reverse=True)
print(sum(dic_sort[K:]))


(n, k) = list(map(int, input().split()))
a_list = [int(i) for i in input().split()]
dic = {}
for i in a_list:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
dic2 = sorted(list(dic.items()), key=lambda x: x[1])
ans = 0
if len(dic) > k:
	num = len(dic) - k
	for i in range(num):
		ans += dic2[i][1]
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = list(set(a))
c = sorted(Counter(a).most_common(), key=lambda x: x[1])
num = len(t) - k
if num < 0:
	print(0)
	return
else:
	ans = 0
	for i in range(num):
		ans += c[i][1]
	print(ans)


from collections import Counter, deque, defaultdict
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
	t[x] += 1
B = []
for x in list(t.values()):
	B.append(x)
B.sort()
if len(B) <= k:
	print(0)
	return
ans = 0
for i in range(0, len(B)):
	ans += B[i]
	if len(B) - (i + 1) <= k:
		break
print(ans)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
L = [0] * n
ans = 0
for a in A:
	L[a - 1] += 1
L = sorted(L)
for i in range(n - k):
	ans += L[i]
print(ans)


import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip()

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a_cnt = sorted(list(Counter(a).values()))
	s = set(a)
	t = max(0, len(s) - k)
	print(sum(a_cnt[0:t]))

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
for x in range(n):
	if a[x] not in d:
		d[a[x]] = 0
	d[a[x]] += 1
ans = 0
ans1 = []
for g in d:
	ans1.append(d[g])
if len(ans1) <= k:
	print(0)
else:
	ans1.sort()
	r = len(ans1) - k
	for t in range(r):
		ans += ans1[t]
	print(ans)


from collections import Counter as C
(_, k) = map(int, input().split())
a = [int(i) for i in input().split()]
c = C(a).values()
d = len(c) - k
if 0 < d:
	print(sum(sorted(c)[:d]))
else:
	print(0)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = [0] * (n + 1)
for i in range(n):
	d[a[i]] += 1
d.sort()
print(sum(d[:n - k + 1]))


import collections as c
(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = c.Counter(x)
s = []
for i in y.items():
	s.append([i[1], i[0]])
s.sort()
ans = 0
for i in range(len(s) - k):
	ans += s[i][0]
print(ans)


from collections import Counter
(_, K) = map(int, input().split())
A = list(map(int, input().split()))
(_, cnt) = zip(*Counter(A).most_common()[::-1])
print(sum(cnt[:len(cnt) - K]))


from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
c = Counter(a)
c = list(c.most_common())
len_c = len(c)
ans = 0
while len_c - k > 0:
	(i, j) = c.pop()
	len_c -= 1
	ans += j
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter(a)
l = len(cnt)
t = l - k
ans = 0
for i in sorted(cnt.values()):
	if t <= 0:
		break
	t -= 1
	ans += i
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * N
for i in range(N):
	B[A[i] - 1] += 1
B.sort()
print(sum(B[0:N - K]))


from collections import Counter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = Counter(a)
if len(set(a)) <= k:
	print(0)
else:
	ci = list(l.values())
	ci.sort()
	i = 0
	cnt = len(ci)
	ans = 0
	while cnt > k:
		cnt -= 1
		ans += ci[i]
		i += 1
	print(ans)


from collections import Counter
(n, k) = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
	cnt = Counter(a)
	ans = sum(sorted(cnt.values())[:num_of_types - k])
print(ans)


from collections import Counter
(_, K) = map(int, input().split())
A = sorted(list(Counter(input().split()).values()))
print(sum(A[:len(A) - K]))


from collections import Counter, deque, defaultdict
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
	t[x] += 1
B = list(t.values())
B.sort()
if len(B) <= k:
	print(0)
	return
ans = sum(B[:len(B) - k])
print(ans)


import operator
from collections import Counter
(n, k) = [int(_) for _ in input().split()]
D = Counter([int(_) for _ in input().split()])
D = dict(sorted(list(D.items()), key=operator.itemgetter(1), reverse=True))
c = 0
i = 0
for _ in D:
	if i >= k:
		c += D[_]
	i += 1
print(c)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b = [0]
c = n
d = 1
for i in range(n - 1):
	if a[i] == a[i + 1]:
		d += 1
		c -= 1
	else:
		b.append(d)
		d = 1
b.append(d)
b.sort()
for i in range(len(b) - 1):
	b[i + 1] += b[i]
print(b[max(0, c - k)])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
from collections import Counter
a1 = Counter(a).most_common()
num = 0
if k < len(a1):
	for i in range(1, len(a1) - k + 1):
		num += a1[-i][1]
	print(num)
else:
	print(0)


(N, K) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
X = [0] * N
for i in range(N):
	X[A[i] - 1] += 1
X = sorted(X, reverse=True)
S = sum(X[:K])
ans = N - S
print(ans)


(_, k) = map(int, input().split())
d = {}
for i in map(int, input().split()):
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
d = sorted(d.values(), reverse=True)
print(sum((v for v in d[k:])))


import collections
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
c = collections.Counter(a)
if len(c) < k:
	print(ans)
	return
l = c.most_common()
for i in range(1, -k + len(c) + 1):
	ans += l[-i][1]
print(ans)


(N, K) = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
d = {}
for n in range(N):
	if d.get(A[n]) == None:
		d[A[n]] = 1
	else:
		d[A[n]] += 1
dn = sorted(list(d.items()), key=lambda x: x[1])
if K >= len(d):
	print(0)
else:
	cnt = 0
	ans = 0
	for n in range(len(dn)):
		ans += dn[n][1]
		cnt += 1
		if cnt == len(d) - K:
			break
	print(ans)


from collections import Counter
(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
CA = Counter(A)
kouho = CA.most_common()[::-1]
ans = 0
idx = 0
while idx < len(CA) - k:
	(key, val) = kouho[idx]
	ans += val
	idx += 1
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * (N + 1)
for i in range(N):
	B[A[i]] += 1
B.sort(reverse=True)
cnt = 0
for i in range(K):
	cnt += B[i]
print(N - cnt)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
A_dict = dict()
for i in range(N):
	if A_dict.get(A[i]) is None:
		A_dict[A[i]] = 1
	else:
		A_dict[A[i]] += 1
A_dict_len = len(list(A_dict.keys()))
ans = 0
A_dict_sorted = sorted(list(A_dict.items()), key=lambda a: a[1])
for i in range(max(0, A_dict_len - K)):
	ans += A_dict_sorted[i][1]
print(ans)


(N, K) = map(int, input().split())
d = [0] * N
A = [int(x) for x in input().split()]
for a in A:
	d[a - 1] += 1
d.sort(reverse=True)
ans = N - sum(d[:K])
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
dic = {}
for i in range(N):
	a = A[i]
	if a not in dic:
		dic[a] = 1
	else:
		dic[a] += 1
dic = sorted(dic.items(), key=lambda x: x[1])
ans = 0
for i in range(max(len(dic) - K, 0)):
	ans += dic[i][1]
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
cnt_A = sorted(Counter(A).values())
ans = 0
if len(cnt_A) <= k:
	print(ans)
else:
	for i in range(len(cnt_A) - k):
		ans += cnt_A[i]
	print(ans)


from collections import Counter
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
cnt = Counter(A)
cnt_sorted = sorted(cnt.items(), reverse=True, key=lambda x: x[1])
sum = 0
for i in range(min(K, len(cnt))):
	sum += cnt_sorted[i][1]
print(N - sum)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
count = {}
for val in A:
	if val in count:
		count[val] += 1
	else:
		count[val] = 1
ans = 0
diff = len(set(A)) - K
if diff > 0:
	count_sorted = sorted(count.items(), key=lambda x: x[1])
	for (k, v) in count_sorted:
		ans += v
		diff -= 1
		if diff == 0:
			break
print(ans)


from collections import Counter
(n, k) = map(int, input().split())
L = Counter(list(map(int, input().split())))
num = max(len(L) - k, 0)
ans = 0
if num == 0:
	print(0)
	return
L2 = sorted(L.values())
print(sum(L2[:num]))


import collections
(N, K) = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
c = collections.Counter(L)
c = c.most_common()
ans = 0
if len(c) > K:
	for i in range(len(c) - K):
		ans += c[len(c) - i - 1][1]
	print(ans)
else:
	print(0)


import collections
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a_cnt = collections.Counter(a)
a_sort = sorted(list(a_cnt.values()), reverse=True)
print(sum(a_sort[k:]))


from collections import Counter

def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	unchange = sum((tuple[1] for tuple in Counter(A).most_common(K)))
	print(N - unchange)
main()


import collections
(N, K) = list(map(int, input().split()))
N_List = list(map(int, input().split()))
Chou_List = collections.Counter(N_List)
if len(Chou_List) <= K:
	print(0)
else:
	Chou_List = sorted(list(Chou_List.values()), reverse=True)
	print(sum(Chou_List[K:]))


from collections import Counter as CC
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
B = CC(A)
C = sorted(B.values())
print(sum(C[:max(0, len(C) - K)]))


import bisect as bs
(N, K) = (int(x) for x in input().split())
A = sorted([int(x) for x in input().split()])
f = lambda X, x: bs.bisect_right(X, x) - bs.bisect_left(X, x)
cnt = sorted([f(A, a) for a in set(A)], reverse=True)
vrt = len(cnt)
print(sum(cnt[K:]) if vrt > K else 0)


from collections import Counter
(n, K) = map(int, input().split())
a = list(map(int, input().split()))
c = Counter()
for x in a:
	c[x] += 1
cv = [(k, x) for (x, k) in c.items()]
cv.sort(reverse=True)
ans = 0
while len(cv) > K:
	(k, _) = cv.pop()
	ans += k
print(ans)


(N, K) = map(int, input().split())
a_list = list(map(int, input().split()))
num_dic = {}
for a in a_list:
	count = num_dic.get(a, 0)
	num_dic[a] = count + 1
replace_num = len(num_dic.keys()) - K
replace_num = 0 if replace_num < 0 else replace_num
ans = 0
for (i, taple) in enumerate(sorted(num_dic.items(), key=lambda x: x[1])):
	if i == replace_num:
		break
	ans += taple[1]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import collections
c = collections.Counter(a)
li = []
ans = 0
for (v, num) in c.items():
	li.append((v, num))
ll = sorted(li, key=lambda x: x[1], reverse=True)
for i in range(k, len(ll)):
	ans += ll[i][1]
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
import collections
a = collections.Counter(A)
b = a.most_common()
ans = 0
if len(b) > K:
	for i in range(K, len(b)):
		ans += b[i][1]
print(ans)


from collections import Counter
(n, k) = list(map(int, input().split()))
a = Counter(list(map(int, input().split())))
a = list(a.items())
a.sort(key=lambda x: x[1])
opt = len(a) - k
ans = 0
if opt > 0:
	for i in range(opt):
		ans += a[i][1]
print(ans)


from collections import Counter
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
L = Counter(A)
ans = N
for (a, cnt) in L.most_common(K):
	ans -= cnt
print(ans)


import collections
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
b = len(collections.Counter(a))
c = collections.Counter(a).most_common()
for i in range(min(k, b)):
	count += c[i][1]
ans = len(a) - count
print(ans)


import collections
(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
C = collections.Counter(A)
KEY = list(C.keys())
count = 0
if len(KEY) > K:
	D = len(KEY) - K
	L = C.most_common()[::-1]
	for ii in range(D):
		count += L[ii][1]
print(count)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
m = [0 for i in range(200001)]
for i in range(N):
	m[A[i]] += 1
m.sort(reverse=True)
ans = 0
for i in range(K, N):
	if m[i] == 0:
		break
	ans += m[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n):
	b[a[i] - 1] += 1
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
	print(sum(c[0:len(c) - k]))
else:
	print(0)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A_dic = {}
A_count = []
for i in range(N):
	if A[i] not in A_dic.keys():
		A_dic[A[i]] = 1
	else:
		A_dic[A[i]] += 1
for i in A_dic.keys():
	A_count.append(A_dic[i])
if len(A_count) <= K:
	print(0)
else:
	ans = 0
	A_count.sort()
	for i in range(len(A_count) - K):
		ans += A_count[i]
	else:
		print(ans)


import operator
(N, K) = map(int, input().split())
lst = list(map(int, input().split()))
x = []
x = set(lst)
if len(x) <= K:
	print(0)
else:
	freq = {}
	for i in lst:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	s = {}
	s = dict(sorted(freq.items(), key=operator.itemgetter(1)))
	cc = abs(len(x) - K)
	v = 0
	for (key, value) in s.items():
		v += s[key]
		cc -= 1
		if cc == 0:
			print(v)
			break


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
temp = 1
V = []
for i in range(N - 1):
	if A[i] == A[i + 1]:
		temp += 1
	else:
		V.append(temp)
		temp = 1
V.append(temp)
V.sort()
ans = N - sum(V[-K:])
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
a = [0] * 200000
b = []
for i in A:
	a[i - 1] += 1
for i in a:
	if i:
		b.append(i)
b.sort()
ans = 0
for i in range(len(b) - K):
	ans += b[i]
print(ans)


from collections import deque
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
nums = [0] * N
for i in range(N):
	nums[A[i] - 1] += 1
nums.sort()
nums = deque(nums)
while True:
	if nums[0] == 0:
		nums.popleft()
	else:
		break
nums = list(nums)
if len(nums) <= K:
	print(0)
else:
	print(sum(nums[:len(nums) - K]))


(n, k) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
c = [0] * (n + 1)
for i in a:
	c[i] += 1
print(sum(sorted(c)[:-k]))


def main():
	(n, k) = map(int, input().split())
	inlis = list(map(int, input().split()))
	indic = dict()
	cnt = 0
	for i in range(n):
		num = inlis[i]
		if num in indic:
			indic[num] += 1
		else:
			indic[num] = 1
			cnt += 1
	if cnt <= k:
		print(0)
	else:
		indic_sort = sorted(indic.items(), key=lambda x: x[1])
		sa = cnt - k
		tmp = 0
		ans = 0
		for j in range(n):
			tmp += 1
			ans += indic_sort[j][1]
			if tmp == sa:
				break
		print(ans)

def __starting_point():
	main()
__starting_point()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
times = [0] * (n + 1)
for i in a:
	times[i] += 1
times.sort()
for i in range(n + 1):
	if times[i] != 0:
		j = i
		break
ans = 0
if len(times) > k - j:
	for i in range(j, len(times) - k):
		ans += times[i]
print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N + 1)]
for a in A:
	B[a] += 1
nums = [b for b in B if b > 0]
nums.sort()
n = len(nums)
if n <= K:
	print(0)
else:
	print(sum(nums[:n - K]))


from collections import Counter
(N, K) = list(map(int, input().split()))
A = Counter(list(map(int, input().split())))
if len(A) > K:
	(values, counts) = list(zip(*A.most_common()[-(len(A) - K):]))
	print(sum(counts))
else:
	print(0)


import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '5 2\n1 1 2 2 5'
		output = '1'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '4 4\n1 1 2 2'
		output = '0'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '10 3\n5 1 3 2 4 1 1 2 3 4'
		output = '3'
		self.assertIO(input, output)

def resolve():
	(N, K) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	an = [0] * N
	for i in a:
		an[i - 1] += 1
	an.sort(reverse=True)
	ans = 0
	for i in an:
		if K == 0:
			ans += i
		else:
			K -= 1
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(N, K) = map(int, input().split())
a_list = list(map(int, input().split()))
counter_list = [0] * N
for i in a_list:
	counter_list[i - 1] += 1
counter_list.sort(reverse=True)
ans = N - sum(counter_list[:K])
print(ans)


(N, K) = list(map(int, input().split()))
A = list(map(int, input().split()))
X = [0 for _ in range(N + 1)]
for a in A:
	X[a] += 1
X.sort(reverse=True)
print(N - sum(X[0:K]))


from collections import Counter

def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def main():
	(n, k) = Input()
	a = sorted(Counter(Input()).items(), key=lambda x: x[1], reverse=True)
	temp = 0
	for i in range(min(k, len(a))):
		temp += a[i][1]
	print(sum((i for (_, i) in a)) - temp)
main()


def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	lst = {}
	for num in A:
		if num in lst:
			lst[num] += 1
		else:
			lst[num] = 1
	lst_sorted = sorted(lst.items(), key=lambda x: x[1])
	len_lst_sorted = len(lst_sorted)
	if len_lst_sorted <= K:
		print(0)
		return
	else:
		ans = 0
		for i in range(len_lst_sorted - K):
			ans += lst_sorted[i][1]
		print(ans)
		return

def __starting_point():
	main()
__starting_point()


import collections
(N, K) = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
l = len(c)
c = list(c.items())
c.sort(key=lambda x: x[1])
ans = 0
for i in c:
	if l <= K:
		break
	ans += i[1]
	l -= 1
print(ans)


(n, k) = map(int, input().split())
Xl = list(map(int, input().split()))
from collections import Counter
Xdic = Counter(Xl)
valuelist = sorted(list(Xdic.values()), reverse=True)
print(sum(valuelist[k:]))