n, k = list(map(int, input().split()))

a = list(map(int, input().split()))

if len(set(a)) == k:

    print((0))

    exit()



d = {}

for i in a:

    if i in d:

        d[i] += 1

    else:

        d[i] = 1



s = sorted(list(d.items()), key=lambda x:x[1])

ans = 0

for j in range(len(s) - k):

    ans += s[j][1]



print(ans)
from collections import Counter



n, k = list(map(int, input().split()))

a = input().split()

c = sorted(list(Counter(a).values()), reverse=True)



print((max(0, sum(c[k:]))))
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if len(set(a)) == k:
    print((0))
    exit()
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
s = sorted(list(d.items()), key=lambda x: x[1])
ans = 0
for j in range(len(s) - k):
    ans += s[j][1]
print(ans)

from collections import Counter

n, k = list(map(int, input().split()))
a = input().split()
c = sorted(list(Counter(a).values()), reverse=True)
print((max(0, sum(c[k:]))))

+from collections import Counter + -a = list(map(int, input().split())) -if len(set(a)) == k: -    print((0)) -    exit() -d = {} -for i in a: -    if i in d: -        d[i] += 1 -    else: -        d[i] = 1 -s = sorted(list(d.items()), key=lambda x: x[1]) -ans = 0 -for j in range(len(s) - k): -    ans += s[j][1] -print(ans) +a = input().split() +c = sorted(list(Counter(a).values()), reverse=True) +print((max(0, sum(c[k:]))))