from collections import defaultdict

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

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



d = defaultdict(int)

for i in A:

    d[i] += 1



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

n =len(d_)

ans = 0

if n <= K:

    print((0))

    exit()

else:

    for i in range(K,n):

        ans += d_[i][1]

print(ans)
from collections import Counter

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

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



d = Counter(A)



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

n =len(d_)

ans = 0

if n <= K:

    print((0))

    exit()

else:

    for i in range(K,n):

        ans += d_[i][1]

print(ans)
from collections import defaultdict

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
d = defaultdict(int)
for i in A:
    d[i] += 1
d_ = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
n = len(d_)
ans = 0
if n <= K:
    print((0))
    exit()
else:
    for i in range(K, n):
        ans += d_[i][1]
print(ans)

from collections import Counter

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
d = Counter(A)
d_ = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
n = len(d_)
ans = 0
if n <= K:
    print((0))
    exit()
else:
    for i in range(K, n):
        ans += d_[i][1]
print(ans)

-from collections import defaultdict +from collections import Counter -d = defaultdict(int) -for i in A: -    d[i] += 1 +d = Counter(A)