CodeEff/ECCO huggingface dataset:
# Original solution
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a
# Python 1st Try

import sys
# from collections import defaultdict
import collections as col
# import pprint
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(ALLNUM, KIND, ball_numbers):
    result = 0
    # prp = pprint.pprint
    counter_result = col.Counter(ball_numbers)
    ball_num_len = len(counter_result)
    counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1])
    # prp(counter_result_sorted)
    if ball_num_len <= KIND:
        return 0
    reduce_kind = ball_num_len - KIND
    # prp(reduce_kind)
    for _, ballCount in counter_result_sorted:
        result += ballCount
        reduce_kind = reduce_kind - 1
        # prp(reduce_kind)
        if reduce_kind <= 0:
            break
    return result


if __name__ == "__main__":
    N, K = MI()
    Ai = list(map(int, sys.stdin.readline().split()))
    # print(Ai)
    print(("{}".format(solver(N, K, Ai))))


# Optimized solution
# Problem: https://atcoder.jp/contests/abc081/tasks/arc086_a
# Python 2nd Try

import sys
from collections import Counter
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return list(map(int, sys.stdin.readline().split()))
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(givenBall, selectKind, ball_num):
    result = 0
    summary_Ball = Counter(ball_num)
    # print("{}".format(list(summary_Ball.values())))
    sortedCount = sorted(list(summary_Ball.values()))
    # print(sortedCount)
    ballAllKind = len(sortedCount)
    changeNumberKind = ballAllKind - selectKind
    if changeNumberKind <= 0:
        result = 0
    else:
        for j in range(0, changeNumberKind, +1):
            result += sortedCount[j]
    return result


if __name__ == "__main__":
    N, K = MI()
    Ai = LI()
    print(("{}".format(solver(N, K, Ai))))
# Original solution
import collections
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
count = collections.Counter(A)
if len(list(count.values())) <= K:
    print((0))
else:
    ans = 0
    for i in range(len(list(count.values())) - K):
        ans += count.most_common()[-(i+1)][1]
    print(ans)


# Optimized solution
import collections
N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
count = collections.Counter(A)
num = len(count)-K
a = sorted(count.values())
print((sum(a[:num])))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list()
for i in range(n):
    b.append(a.count(i+1))
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
    print((sum((c[0:len(c)-k]))))
else:
    print((0))

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[a[i]-1] += 1
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
    print((sum((c[0:len(c)-k]))))
else:
    print((0))
# Original solution
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

X = set(A)
L = len(X)

S= []
for x in X:
    n = A.count(x)
    S.append(n)

S = sorted(S)

ans = sum(S[:max(0,L - K)])

print(ans)

# Optimized solution
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

X = [0] * N

for i in range(N):
    X[A[i] - 1] += 1

X = sorted(X, reverse=True)

S = sum(X[:K])

ans = N - S

print(ans)
# Original solution
import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
counter = 0
collection = collections.Counter(A)
k = len(collection)
if k > K:
  change_n = k - K
  for i in range(change_n):
    min_k = collection.most_common()[-1-i][1]
    counter += min_k

print(counter)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
counter = 0
dic = {}

for a in A:
  if a in list(dic.keys()):
    dic[a] += 1
  else:
    dic[a] = 1

k = len(dic)
v = sorted(dic.values())
if k > K:
  change_n = k -K
  for i in range(change_n):
    min_k = v[i]
    counter += min_k

print(counter)
# Original solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    ball_count, kind_count = list(map(int, input().split()))
    ball_numbers = Counter(list(map(int, input().split())))
    sorted_ball_numbers = sorted(list(ball_numbers.items()), key=lambda x: x[1])
    ball_number_key_count = len(list(ball_numbers.keys()))

    need_rewritten_count = 0
    diff_count = ball_number_key_count - kind_count

    if diff_count > 0:
        for i, (key, value) in enumerate(sorted_ball_numbers):
            if diff_count > i:
                need_rewritten_count += value

    print(need_rewritten_count)


# Optimized solution
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    ball_count, kind_count = list(map(int, input().split()))
    ball_numbers = Counter(list(map(int, input().split())))
    sorted_ball_numbers = sorted(ball_numbers.values())
    print((sum(sorted_ball_numbers[:-kind_count])))
# Original solution
import collections
def solve(n, k, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    key_num = len(list(counter.keys()))
    if key_num > k:
        tmp = sorted(list(counter.items()), key=lambda x: x[1])
        ans = sum([v for k, v in tmp[: key_num - k]])
    else:
        ans = 0

    return ans

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print((solve(n, k, a_list)))


# Optimized solution
import collections
def solve(n, k, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    tmp = sorted(list(counter.values()), reverse=True)
    ans = n - sum(tmp[:k])
    
    return ans

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print((solve(n, k, a_list)))
# Original solution
n,k=list(map(int,input().split()))
A=list(map(int,input().strip().split(" ")))
ANS=[]
for i in range(200000):
    ANS.append(A.count(i))
ANS.sort(reverse=True)
B=[e for e in ANS if e>0]

P=[]
if len(B)<=k:
    print((0))
else:
    for i in B[k:]:
        P.append(i)
    print((sum(P)))

# Optimized solution
n,k=list(map(int,input().split()))
A=list(map(int,input().strip().split(" ")))
dict={}

for i in A:
    if i in dict:
        dict[i] += 1
    else:
        dict[i] = 1

X=[]
sorted_A = sorted(list(dict.items()), key=lambda x: x[1], reverse=True)
for i,v in sorted_A:
    X.append(v)

ans=0
if len(X)>k:
    for i in X[k:]:
        ans+=i
print(ans)
# Original solution
import collections
import sys
n,k = list(map(int,input().split()))
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
if len(a) > k:
    for i in range(len(a)-1):
        if len(a) - k - i > 0:
            p += c.most_common()[-1-i][1]
        else:
            print(p)
            sys.exit()
else:
    print((0))

# Optimized solution
import sys
n,k = list(map(int,input().split()))
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print((0))
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()
# Original solution
import collections

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
#print(arr)
b=sorted([arr[i][1] for i in range(now_k)])
#print(b)
cnt=now_k
cnt2=0
flg=0
for i in b:
  cnt-=1
  cnt2+=i
  if cnt==k:
    print(cnt2)
    flg=1
    break
if flg==0:
  print((0))

# Optimized solution
import collections

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

now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print((sum(b[:d])))
# Original solution
import collections

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

now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print((sum(b[:d])))

# Optimized solution
from collections import Counter 

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

now_k=len(set(a))
d=now_k-k
arr=Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print((sum(b[:d])))
# Original solution
import sys
from collections import Counter

n, k, *a = list(map(int, sys.stdin.read().split()))

def main():
    c = Counter(a)
    l = len(c)
    if l <= k:
        return 0

    c = sorted(list(c.items()), key=lambda x: x[1])
    res = 0
    for i in range(l - k):
        res += c[i][1]

    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

# Optimized solution
import sys
from collections import Counter

n, k, *a = list(map(int, sys.stdin.read().split()))

def main():
    c = Counter(a)
    res = sum(sorted(c.values())[:-k])
    print(res)

if __name__ ==  '__main__':
    main()
# Original solution
import sys
import collections
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = list(map(int, input().split()))
    c = collections.Counter(input().split())
    print((sum(sorted(list(c.values()), reverse=True)[K:])))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import collections
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = list(map(int, input().split()))
    c = collections.Counter(input().split())
    c = sorted(c.values())
    k = len(c) - K
    if k <= 0:
        print((0))
    else:
        print((sum(c[:k])))


if __name__ == '__main__':
    main()
# Original solution
import collections

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a_cnt = collections.Counter(a).most_common()[::-1]
ans = 0
n = len(list(set(a)))
if n <= k:
    print((0))
    exit()
for v in range(n):
    ans += a_cnt[v][1]
    n -= 1
    if n <= k:
        print(ans)
        exit()


# Optimized solution
import collections

n, k = list(map(int, input().split()))
values = list(map(int, input().split()))
obj, cnt = list(zip(*collections.Counter(values).most_common()[::-1]))
cnt = list(cnt)
diff = max(0, len(cnt) - k)
ans = sum(cnt[:diff])
print(ans)
# Original solution
from collections import Counter

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

D = Counter(A)
K = []
for key in list(D.keys()):
    K.append(key)
if len(set(K)) <= k:
    print((0))
else:
    V = []
    for v in list(D.values()):
        V.append(v)
    V.sort(reverse=True)
    print((n-sum(V[:k])))

# Optimized solution
from collections import Counter

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

D = Counter(A)
V = []
for v in list(D.values()):
    V.append(v)
V.sort(reverse=True)
print((max(n-sum(V[:k]),0)))
# Original solution
n,k=[int(i) for i in input().split()]

a_list=[int(i) for i in input().split()]
#print(a_list)

dic={}
for i in a_list:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1

#print(dic)
#print(len(dic))


#書き換えなくてよい    
if len(dic)<=k:
    print((0))
else:
    ans=sorted(list(dic.items()),key=lambda x:x[1],reverse=True)
    b_list=ans[k:]
    ans_sum=0
    for i in b_list:
        ans_sum+=i[1]
    print(ans_sum)
    


# Optimized solution
n,k=[int(i) for i in input().split()]

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

a_dic={}
for i in range(n):
    if a_list[i] not in a_dic:
        a_dic[a_list[i]]=1
    else:
        a_dic[a_list[i]]+=1
        


if len(a_dic)<=k:
    print((0))
else:
    #値を取り出す
    a_value=list(a_dic.values())
    
    a_value.sort(reverse=True)
    
    print((sum(a_value[k:])))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A1:
    AN[a] = A.count(a)
AN = sorted(list(AN.items()), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(list(AN.items()), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')
# Original solution
import collections
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
count=0
b=len(collections.Counter(a))
#print(b)
for i in range(min(k,b)):
    count+=collections.Counter(a).most_common()[i][1]
#    print(count)
ans=len(a)-count
print(ans)

# Optimized solution
import collections
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
count=0
b=len(collections.Counter(a))
c=collections.Counter(a).most_common()
#print(b)
for i in range(min(k,b)):
    count+=c[i][1]
#    print(count)
ans=len(a)-count
print(ans)
# Original solution
from collections import defaultdict
n, k = list(map(int, input().split()))
li = list(map(int, input().split()))

s = set(li)
ns = [li.count(i) for i in s]
ns.sort()

if len(ns) <= k:
    print((0))
else:
    print((sum(ns[:-k])))


# Optimized solution
n, k = list(map(int, input().split()))
li = list(map(int, input().split()))
li.sort()

ar = []
tmp = -1
for a in li:
    if a != tmp:
        tmp = a
        ar.append(1)
    else:
        ar[-1] += 1
ar.sort()

if len(ar) <= k:
    print((0))
else:
    print((sum(ar[:-k])))
# Original solution
from collections import Counter

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

count = []
c = Counter(a) # dict {'a': 3, 'b': 4, ...}
for i in c:
    count.append(c[i])

count.sort(reverse = True)
print((n - sum(count[:k])))


# Optimized solution
from collections import Counter

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

c = Counter(a) # Counter({1: 2, 2: 2, 5: 1})
count = list(c.values()) # [2, 2, 1] (type: 'dict_values')

l_count = list(count) # to list 
l_count.sort(reverse = True) # to descending order

print((n - sum(l_count[:k]))) # n - (sum of first k values from count[])
# Original solution
N, K = list(map( int, input().split() ))
A = list( map( int, input().split() ) )

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

print(( sum( numAppeared[i] for i in range(K,N) ) ))

# Optimized solution
N, K = list(map( int, input().split() ))
A = list( map( int, input().split() ) )

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

# print( sum( numAppeared[i] for i in range(K,N) ) )
print(( sum( numAppeared[K:N] ) ))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        ns.append(t)
ns.sort()
ans = 0
while len(ns) > K:
    ans += ns[0]
    ns = ns[1:]
print(ans)


# Optimized solution
import heapq

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

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        heapq.heappush(ns, t)
ans = 0
while len(ns) > K:
    ans += heapq.heappop(ns)
print(ans)
# Original solution
n, k = input().split()
n, k = int(n), int(k)
balls = [int(x) for x in input().split()]
dic = {}
for x in balls:
	if x not in dic:
		dic[x] = 1
	else:
		dic[x] += 1
change = 0
qnt = list(dic.values())
qnt.sort()
while len(qnt) > k:
	change += qnt[0]
	qnt.pop(0)
print(change)

# Optimized solution
n, k = input().split()
n, k = int(n), int(k)
balls = input().split()
dic = {}
for x in balls:
	if x not in dic:
		dic[x] = 1
	else:
		dic[x] += 1
change = 0
qnt = list(dic.values())
qnt.sort()
dif = len(qnt) - k
for x in range(0, dif):
	change += qnt[x]
print(change)
# Original solution
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
D = dict.fromkeys(list(range(1,n+1)),0)
ans = 0
for a in A:
  D[a] += 1
D = sorted(list(D.items()), key=lambda x:x[1])
for i in range(n-k):
  ans += D[i][1]
print(ans)

# Optimized solution
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
L = [0] * n
ans = 0

for a in A:
  L[a-1] += 1
L = sorted(L)
for i in range(n-k):
  ans += L[i]

print(ans)
# Original solution
import collections
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
dic = collections.Counter(a)
#for i in a:
#    if i in dic:
#        dic[i] += 1
#    else:
#        dic[i] = 1
dic = sorted(list(dic.items()), key=lambda x: x[1])
while len(dic) > k:
    ans += dic[0][1]    
    del dic[0]
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(list(dic.items()), key=lambda x: x[1])
#while len(dic) > k:
#    ans += dic[0][1]    
#    del dic[0]
for i in range(len(dic)-k):
    ans += dic[i][1]
print(ans)
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
d={}
for i in a:
    d[i]=d.get(i,0)+1
c=0
while len(d)>k:
    x=min(d, key=d.get)
    c+=d[x]
    del d[x]
print(c)


# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=set(a)
l=[0]*(n+1)
for i in range(n):
    l[a[i]]+=1
l=[i for i in l if i>0]
l.sort()
le=len(s)
c=0
for i in range(len(l)):
    if le<=k:
        break
    else:
        c+=l[i]
        le-=1
print(c)
# Original solution
import copy
import collections

def calc(k, balls):
    balls_count = set(copy.copy(balls))
    change_count = 0
    flg = True

    while flg == True:
        if len(balls_count) <= int(k):
            flg = False
            return change_count
        else:
            c = collections.Counter(balls)
            most_common = c.most_common()[-1]
            balls = [i for i in balls if i != most_common[0]]
            balls_count = sorted(set(copy.copy(balls)))
            change_count += int(most_common[1])


_ = input().split()
k = _[1]
balls = sorted(input().split())

print((calc(k, balls)))

# Optimized solution
import copy
import collections

def calc(k, balls):
    dif = len(set(copy.copy(balls))) - int(k)
    change_count = 0

    if dif <= 0:
        return change_count
    else:
         c = collections.Counter(balls)
         most_common = c.most_common()[::-1]
         for x in most_common:
             change_count = change_count +  x[1]
             dif = dif - 1
             if dif <= 0 :
                break
         return change_count


_ = input().split()
k = _[1]
balls = sorted(input().split())

print((calc(k, balls)))
# Original solution
import collections
n, k = list(map(int,input().split()))
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
if len(set(a)) <= k:
    print(ans)
    exit()
for i in range(0,k):
    ans += c.most_common()[i][1]
print((n-ans))

# Optimized solution
import collections
n, k = list(map(int,input().split()))
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0
cnt = 0
if len(set(a)) <= k:
    print(ans)
    exit()
for  tuple in c.most_common():
    ans += tuple[1]
    cnt += 1
    if cnt == k:
      print((n-ans))
      exit()
# Original solution
from collections import Counter
N, K = list(map(int, input().split()))
a = Counter(list(map(int, input().split())))
if N == K:
    print((0))
else:
    num = list(a.values())
    if len(num) <= K:
        print((0))
    else:
        print((sum(sorted(num)[:-K])))

# Optimized solution
from collections import Counter
N, K = list(map(int, input().split()))
A = sorted(list(Counter(list(map(int, input().split()))).values()))
if N == K:
    print((0))
elif len(A) <= K:
    print((0))
else:
    print((sum(A[:-K])))
# Original solution
from collections import Counter

N,K = list(map(int,input().split()))
A=list(map(int,input().split()))
count = Counter(A)
diff = len(count)-K

ans=0

if diff<=0:
    print((0))
else:
    for i in range(diff):
        ans+=count.most_common()[len(count)-i-1][1]
    print(ans)

# Optimized solution
from collections import Counter

N,K = list(map(int,input().split()))
A=list(map(int,input().split()))
count = Counter(A)
count = count.most_common()
diff = len(count)-K
ans=0
if diff>0:
    for i in range(diff):
        ans+=count[len(count)-i-1][1]

print(ans)
# Original solution
N, K = list(map(int, input().split()))

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

C = list(set(A))

B = len(C) 

x = B - K

ans = 0

figure_list = [0] * B

if x<=0:
    print('0')
else:
    for i in range(B):
        stock = int(C[i])
        counter = 0
        for ii in range(N):
            if stock == A[ii]:
                counter += 1
        figure_list[i] = counter

    figure_list = sorted(figure_list)

    for i in range(B-K):
        ans += figure_list[i]

    print(ans)    

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

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

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

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

ans = 0
count = 0

if x<=0:
    print('0')
else:
    for key, value in d:
        ans = ans + value
        count = count + 1
        if count == x:
            print(ans)
            break
# Original solution
from collections import Counter

N, K = list(map(int, input().split()))
A = input().split()
cnt = Counter(A)
del_num = len(cnt) - K

print((sum(sorted(cnt.values())[:del_num])))

# Optimized solution
from collections import Counter

n,k = list(map(int, input().split()))
a = input().split()
cnt = Counter(a)
del_num = len(cnt) - k

print((sum(sorted(cnt.values())[:del_num])))
# Original solution
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
li = []
for i in range(N+1):
    cnt = A.count(i+1)
    if cnt>0:
        li.append(cnt)
li.sort(reverse=True)
print((sum(li[K:])))

# Optimized solution
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
li = {}
for i in A:
    c = li.setdefault(i,0)
    li[i] = c + 1
    # print(c)
w = len(list(li.keys())) - K
# print(w)
# print(len(li.keys()))
ans = sorted(li.values())
# print(ans)
if w > 0:
    print((sum(ans[:w])))
else:
    print((0))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
C = list(set(A))
B = [0 for i in range(len(C))]
for a in A:
    B[C.index(a)] += 1
print((sum(sorted(B)[:-K])))

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = {i:0 for i in set(A)}
for a in A:
    B[a] += 1
print((sum(sorted(B.values())[:-K])))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = {i:0 for i in set(A)}
for a in A:
    B[a] += 1
print((sum(sorted(B.values())[:-K])))

# Optimized solution
N, K = list(map(int, input().split()))
B = {}
for i in input().split():
    if i in B:
        B[i] += 1
    else:
        B[i] = 1
print((sum(sorted(B.values())[:-K])))
# Original solution
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
listA = list(listA.values())
listA.sort()
times = len(listA) - K
# print(times,len(listA),K)
num = 0

if times <= 0:
    num = 0
else:
    for _ in range(times):
        num += listA.pop(0)

print(num)



# Optimized solution
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input().split())
# print(listA)
listA = list(listA.values())
listA.sort()
times = len(listA) - K

num = 0

if times <= 0:
    num = 0
else:
    for i in range(times):
        num += listA[i]

print(num)