from collections import defaultdict



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

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

d = defaultdict(int)



for x in a:

  d[x] += 1



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

ans = 0

cnt = 0

for x in new_d:

  if(cnt < len(new_d) - k):

    ans += x[1]

    cnt += 1

  else:

    break

print(ans)
from collections import Counter

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

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

c=Counter(a)

v=list(c.values())

n=len(v)

if n>k:

    ans=sum(sorted(v)[:n-k])

    print(ans)

else:

    print((0))

from collections import defaultdict

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = defaultdict(int)
for x in a:
    d[x] += 1
new_d = sorted(list(d.items()), key=lambda x: x[1])
ans = 0
cnt = 0
for x in new_d:
    if cnt < len(new_d) - k:
        ans += x[1]
        cnt += 1
    else:
        break
print(ans)

from collections import Counter

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
c = Counter(a)
v = list(c.values())
n = len(v)
if n > k:
    ans = sum(sorted(v)[: n - k])
    print(ans)
else:
    print((0))

-from collections import defaultdict +from collections import Counter -d = defaultdict(int) -for x in a: -    d[x] += 1 -new_d = sorted(list(d.items()), key=lambda x: x[1]) -ans = 0 -cnt = 0 -for x in new_d: -    if cnt < len(new_d) - k: -        ans += x[1] -        cnt += 1 -    else: -        break -print(ans) +c = Counter(a) +v = list(c.values()) +n = len(v) +if n > k: +    ans = sum(sorted(v)[: n - k]) +    print(ans) +else: +    print((0))