N, K = list(map(int, input().split()))

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



D = {}

for a in A:

    if a not in D:

        D[a] = 1

    else:

        D[a] += 1

E = sorted(D.values())

c = 0

i = 0

l = len(D)

while l > K:

    c += E[i]

    l -= 1

    i += 1

print(c)
from collections import Counter

N, K = list(map(int, input().split()))

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

C = Counter(A)

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

k = len(C)

c = 0

for i in range(k - K):

    k, v = C[i]

    c += v



print(c)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
D = {}
for a in A:
    if a not in D:
        D[a] = 1
    else:
        D[a] += 1
E = sorted(D.values())
c = 0
i = 0
l = len(D)
while l > K:
    c += E[i]
    l -= 1
    i += 1
print(c)

from collections import Counter

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
C = Counter(A)
C = sorted(list(C.items()), key=lambda x: x[1])
k = len(C)
c = 0
for i in range(k - K):
    k, v = C[i]
    c += v
print(c)

+from collections import Counter + -D = {} -for a in A: -    if a not in D: -        D[a] = 1 -    else: -        D[a] += 1 -E = sorted(D.values()) +C = Counter(A) +C = sorted(list(C.items()), key=lambda x: x[1]) +k = len(C) -i = 0 -l = len(D) -while l > K: -    c += E[i] -    l -= 1 -    i += 1 +for i in range(k - K): +    k, v = C[i] +    c += v