from collections import Counter

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

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

cnt = Counter(a)

mo = cnt.most_common()[::-1]

#print(mo)

ans = 0

for i in range(max(0,len(mo)-k)):

    ans += mo[i][1]

print(ans)

from collections import Counter

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

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

cnt = Counter(a)

mo = sorted(cnt.values())

#print(mo)

ans = 0

for i in range(max(0,len(mo)-k)):

    ans += mo[i]

print(ans)

from collections import Counter

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = Counter(a)
mo = cnt.most_common()[::-1]
# print(mo)
ans = 0
for i in range(max(0, len(mo) - k)):
    ans += mo[i][1]
print(ans)

from collections import Counter

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = Counter(a)
mo = sorted(cnt.values())
# print(mo)
ans = 0
for i in range(max(0, len(mo) - k)):
    ans += mo[i]
print(ans)

-mo = cnt.most_common()[::-1] +mo = sorted(cnt.values()) -    ans += mo[i][1] +    ans += mo[i]