import collections

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

a=[int(i) for i in input().split()]

cnt=collections.Counter(a)

shu=len(list(cnt.values()))

ans=0

if shu<=k:

    print(ans)

else:

    x=list(cnt.values())

    x.sort()

    for i in range(shu-k):

        ans+=x[i]

    print(ans)
import collections as C

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

x=list(C.Counter([int(i) for i in input().split()]).values())

shu=len(x)

if shu<=k:

    print((0))

else:

    x.sort()

    print((sum(x[:shu-k])))
import collections

n, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
cnt = collections.Counter(a)
shu = len(list(cnt.values()))
ans = 0
if shu <= k:
    print(ans)
else:
    x = list(cnt.values())
    x.sort()
    for i in range(shu - k):
        ans += x[i]
    print(ans)

import collections as C

n, k = list(map(int, input().split()))
x = list(C.Counter([int(i) for i in input().split()]).values())
shu = len(x)
if shu <= k:
    print((0))
else:
    x.sort()
    print((sum(x[: shu - k])))

-import collections +import collections as C -a = [int(i) for i in input().split()] -cnt = collections.Counter(a) -shu = len(list(cnt.values())) -ans = 0 +x = list(C.Counter([int(i) for i in input().split()]).values()) +shu = len(x) -    print(ans) +    print((0)) -    x = list(cnt.values()) -    for i in range(shu - k): -        ans += x[i] -    print(ans) +    print((sum(x[: shu - k])))