from collections import defaultdict

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

balls = defaultdict(int)

for b in input().split():

    balls[b] += 1

types = len(list(balls.keys()))

balls = sorted(list(balls.values()), reverse=True)

ans = 0

while types > K:

    ans += balls.pop()

    types -= 1

print(ans)

# 解説版



from collections import defaultdict

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

balls = defaultdict(int)

for b in input().split():

    balls[b] += 1

balls = sorted(balls.values())

print((N - sum(balls[-K:])))

from collections import defaultdict

N, K = list(map(int, input().split()))
balls = defaultdict(int)
for b in input().split():
    balls[b] += 1
types = len(list(balls.keys()))
balls = sorted(list(balls.values()), reverse=True)
ans = 0
while types > K:
    ans += balls.pop()
    types -= 1
print(ans)

# 解説版
from collections import defaultdict

N, K = list(map(int, input().split()))
balls = defaultdict(int)
for b in input().split():
    balls[b] += 1
balls = sorted(balls.values())
print((N - sum(balls[-K:])))

+# 解説版 -types = len(list(balls.keys())) -balls = sorted(list(balls.values()), reverse=True) -ans = 0 -while types > K: -    ans += balls.pop() -    types -= 1 -print(ans) +balls = sorted(balls.values()) +print((N - sum(balls[-K:])))