from collections import Counter



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

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



D = Counter(A)

K = []

for key in list(D.keys()):

    K.append(key)

if len(set(K)) <= k:

    print((0))

else:

    V = []

    for v in list(D.values()):

        V.append(v)

    V.sort(reverse=True)

    print((n-sum(V[:k])))
from collections import Counter



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

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



D = Counter(A)

V = []

for v in list(D.values()):

    V.append(v)

V.sort(reverse=True)

print((max(n-sum(V[:k]),0)))
from collections import Counter

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
D = Counter(A)
K = []
for key in list(D.keys()):
    K.append(key)
if len(set(K)) <= k:
    print((0))
else:
    V = []
    for v in list(D.values()):
        V.append(v)
    V.sort(reverse=True)
    print((n - sum(V[:k])))

from collections import Counter

n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
D = Counter(A)
V = []
for v in list(D.values()):
    V.append(v)
V.sort(reverse=True)
print((max(n - sum(V[:k]), 0)))

-K = [] -for key in list(D.keys()): -    K.append(key) -if len(set(K)) <= k: -    print((0)) -else: -    V = [] -    for v in list(D.values()): -        V.append(v) -    V.sort(reverse=True) -    print((n - sum(V[:k]))) +V = [] +for v in list(D.values()): +    V.append(v) +V.sort(reverse=True) +print((max(n - sum(V[:k]), 0)))