import numpy as np

st=input().split()

N=int(st[0]);K=int(st[1])

S=set([])

st=input().split()

P=[0]*(N+1)

Q=[0]*(N+1)

for i in range(N):

    k=int(st[i])

    S.add(k)

    P[k-1]+=1

    Q[P[k-1]-1]-=1

    Q[P[k-1]]+=1

out=0

change=0

count=0

if len(S)<=K:

    print((0))

else:

    for i in range(1,N+1):

        flag=1

        for j in range(Q[i]):

            change+=i

            count+=1

            if count==max([len(S)-K,0]):

                flag=0

                break

        if flag==0:

            break

    print(change)

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

D=dict()

for i in input().split():

    if i in D:

        D[i]+=1

    else:

        D[i]=1

L=[]

for i in D:

    L.append(D[i])

L.sort()

print((sum(L[:-K])))
import numpy as np

st = input().split()
N = int(st[0])
K = int(st[1])
S = set([])
st = input().split()
P = [0] * (N + 1)
Q = [0] * (N + 1)
for i in range(N):
    k = int(st[i])
    S.add(k)
    P[k - 1] += 1
    Q[P[k - 1] - 1] -= 1
    Q[P[k - 1]] += 1
out = 0
change = 0
count = 0
if len(S) <= K:
    print((0))
else:
    for i in range(1, N + 1):
        flag = 1
        for j in range(Q[i]):
            change += i
            count += 1
            if count == max([len(S) - K, 0]):
                flag = 0
                break
        if flag == 0:
            break
    print(change)

N, K = list(map(int, input().split()))
D = dict()
for i in input().split():
    if i in D:
        D[i] += 1
    else:
        D[i] = 1
L = []
for i in D:
    L.append(D[i])
L.sort()
print((sum(L[:-K])))

-import numpy as np - -st = input().split() -N = int(st[0]) -K = int(st[1]) -S = set([]) -st = input().split() -P = [0] * (N + 1) -Q = [0] * (N + 1) -for i in range(N): -    k = int(st[i]) -    S.add(k) -    P[k - 1] += 1 -    Q[P[k - 1] - 1] -= 1 -    Q[P[k - 1]] += 1 -out = 0 -change = 0 -count = 0 -if len(S) <= K: -    print((0)) -else: -    for i in range(1, N + 1): -        flag = 1 -        for j in range(Q[i]): -            change += i -            count += 1 -            if count == max([len(S) - K, 0]): -                flag = 0 -                break -        if flag == 0: -            break -    print(change) +N, K = list(map(int, input().split())) +D = dict() +for i in input().split(): +    if i in D: +        D[i] += 1 +    else: +        D[i] = 1 +L = [] +for i in D: +    L.append(D[i]) +L.sort() +print((sum(L[:-K])))