Problem:
 Score : 300 points    Problem Statement Takahashi has N balls. Initially, an integer A_i is written on the i -th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.      Constraints  1 \leq K \leq N \leq 200000  1 \leq A_i \leq N  All input values are integers.         Input Input is given from Standard Input in the following format:  N  K  A_1  A_2 ... A_N       Output Print the minimum number of balls that Takahashi needs to rewrite the integers on them.        Sample Input 1 5 2
1 1 2 2 5      Sample Output 1 1  For example, if we rewrite the integer on the fifth ball to 2 , there are two different integers written on the balls: 1 and 2 .
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1 .       Sample Input 2 4 4
1 1 2 2      Sample Output 2 0  Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.       Sample Input 3 10 3
5 1 3 2 4 1 1 2 3 4      Sample Output 3 3

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

a.sort()
count = 1
b = []

for i in range(n-1):
    if a[i] != a[i+1]:
        b.append(count)
        count = 1
    else:
        count += 1

b.append(count)

b.sort(reverse=True)

count = 0
if k < len(b):
    for i in range(k, len(b)):
        count += b[i]

print(count)

Solution (Python):
n, k = map(int,input().split())
A = list(map(int,input().split()))
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
B = sorted(nums.values())
m = len(B) - k
ans = 0
for i in range(m):
    ans += B[i]
print(ans)

Solution (Python):
import collections

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

counter = collections.Counter(a)
counter_sorted = sorted(counter.items(), key=lambda x: x[1], reverse=True)
ans = n
for i in range(min(k, len(counter_sorted))):
    ans -= counter_sorted[i][1]
print(ans)

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

ass_a = {}
for aa in A:
    if aa not in ass_a:
        ass_a[aa] = 1
    else:
        ass_a[aa] += 1
ass_a = sorted(ass_a.items(), key=lambda x:x[1])

if len(ass_a) <= K:
    print(0)
else:
    ans = 0
    for i in range(len(ass_a)-K):
        ans += ass_a[i][1]
    print(ans)

Solution (Python):
import collections

n, k = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
nums = collections.Counter(A)

l = len(nums)

if l <= k:
    print(0)
    quit()


ans = 0
for c in sorted(nums.values()):
    ans += c
    l -= 1
    if l <= k:
        break
print(ans)

Solution (Python):

import collections

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

ca = collections.Counter(A)

cc = ca.most_common()

cnt = 0
for i in range(min(K, len(cc))):
    cnt += cc[i][1]

print(len(A) - cnt)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    A = string_to_int(inputs[1])
    counter = collections.Counter(A)
    i = len(counter)
    values = counter.most_common()
    change_num = 0
    while i > K:
        change_num += (values[i-1][1])
        i -= 1
    return change_num


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Solution (Python):
import collections

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

c = collections.Counter(A)

cnt = 0
most_common = c.most_common()
if K < len(c.keys()):
    for i in range(1,abs(len(c.keys()) - K)+1):
            cnt += most_common[-i][1]
print(cnt)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
ary = Counter(list(map(int,input().split())))
if len(ary.keys()) > k:
    print(sum(sorted(ary.values())[:len(ary.keys())-k]))
else:print(0)

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

cnt = [0] * (N+1)

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

cnt.sort(reverse = True)

print(sum(cnt[K:]))

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = Counter([int(x) for x in input().split()])
a_ = sorted(a.values())

res = sum(a_[:len(a_)-k])

print(res)

Solution (Python):
from collections import Counter

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

if len(ary.keys()) <= k:
    print(0)
    exit()

print(sum(sorted(ary.values())[:len(ary.keys())-k]))

Solution (Python):
from collections import defaultdict as dd
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = dd(int)
for i in range(N):
  D[A[i]] += 1
j = len(D)-K
ans = 0
for i in sorted(D.values()):
  if j <= 0: break
  ans += i
  j -= 1
print (ans)

Solution (Python):
n, k = map(int, input().split())
A = list(map(int, input().split()))
import collections
dic = collections.Counter(A)
Nums = sorted(dic.values())
print(sum(Nums[:len(Nums) - k]))

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=Counter(a).values()
d=list(b)
d.sort()
c=set(a)
num=0
for i in range(len(c)-k):
  num+=d[i]
print(num)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
ary = Counter(list(map(int,input().split())))
if len(ary.keys()) <= k:print(0);exit()
print(sum(sorted(ary.values())[:len(ary.keys())-k]))

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = list(map(str, input().split()))
A.sort()
A_set = list(set(A))
A_set.sort()
c = Counter(A)
if len(A_set) <= K:
    print(0)
    exit()
lists = []
for i in range(len(A_set)):
    lists.append(c[str(A_set[i])])
cnt = 0
lists.sort()
for i in range(len(lists) - K):
    cnt += lists[i]
print(cnt)

Solution (Python):
from collections import Counter

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

A = Counter(A).most_common()

count = 0

if len(A) > k:
    for i in range(len(A)-k):
        count += A[-1-i][1]

print(count)

Solution (Python):


from collections import Counter

def main(N,K,A):
    change = max(len(set(A))-K,0)
    ans = 0
    A_count = Counter(A)
    for a in A_count.most_common()[:-change-1:-1]:
        ans += a[1]
    print(ans)
    
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    main(N,K,A)

Solution (Python):
def cc081():
    import sys
    from collections import Counter

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

    dan = Counter(an)

    l = len(dan)
    if l <= k:
        print(0)
        sys.exit()

    l -= k
    cnt = 0
    for ke,va in dan.most_common()[::-1]:
        cnt += va
        l -= 1
        if l <= 0:
            break

    print(cnt)

cc081()

Solution (Python):
import collections
N,K=map(int,input().split())
A=collections.Counter(list(map(int,input().split())))
a=sorted(A.values())
print(sum(a[0:len(a)-K]))

Solution (Python):
import collections
n, k = map(int, input().split())
a = collections.Counter(list(map(int, input().split())))
a = sorted(a.items(), key=lambda x: x[1])

ans = 0
for i in range(len(a) - k):
    ans += a[i][1]
print(ans)

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

S = set(A)

if len(S) <= K:
  print(0)
else:
  ch = len(S) - K
  INF = 10**7
  X = [INF] * (N + 1)
  for i in range(N):
    if X[A[i]] == INF:
      X[A[i]] = 1
    else:
      X[A[i]] += 1 
  X.sort()
  print(sum(X[:ch]))

Solution (Python):
import collections
n,k = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
li = c.most_common()
count = m = len(li)
ans = 0
for i in range(1,m+1):
    if count <= k:
        break
    count -= 1
    ans += li[-i][1]
print(ans)

Solution (Python):
import sys
from collections import defaultdict
N, K = map(int, input().split())
a = list(map(int, input().split()))

seta = set(a)
cntK = len(seta)
cnta = [0] * cntK
if cntK <= K:
    print(0)
    sys.exit()

d = defaultdict(int)
for key in a:
    d[key] += 1

dtmp = sorted(d.items(), key=lambda x: x[1])
cnt = 0
for i in range(cntK - K):
    cnt += dtmp[i][1]
print(cnt)

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

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

t=0

a = Counter(A)
total=0
n = len(a)
if n-K > 0:
    for i, j in zip(range(n-K),a.most_common()[::-1]):
        total +=j[1]
    print(total)
else:print(0)

Solution (Python):
import collections

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

c = collections.Counter(A)
l = len(c)

if l <= K:
  print("0")
else:
  times = 0
  value = 0

  for k,v in sorted(c.items(), key=lambda x: -x[1]):
    if times >=K:
      break
    value += v
    times += 1
  
  print(N-value)

Solution (Python):
from collections import Counter

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

c = Counter(A)
ans = 0
size = len(c.keys())

if size > K:
    temp = size - K
    ans += sum(v for _, v in sorted(c.items(), key=lambda x: x[1])[:temp])

print(ans)

Solution (Python):
import collections
n, k = map(int, input().split())
l = list(map(int, input().split()))
S = collections.Counter(l)
S = sorted(S.values())
print(sum(S[:len(S)-k]))

Solution (Python):
def resolve():
    N, K = map(int, input().split())
    targets = list(map(str, input().split()))
    targets_dict = {}

    for i in range(N):
        if targets[i] not in targets_dict:
            targets_dict[targets[i]] = 1
        else:
            targets_dict[targets[i]] += 1

    need_reduce = len(targets_dict) - K

    if need_reduce <= 0:
        print(0)
    else:
        ans = 0
        targets_dict = sorted(targets_dict.items(), key=lambda x: x[1])
        for i in range(need_reduce):
            ans += targets_dict[i][1]
        print(ans)
       
resolve()

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

a_dic = {}
for i in range(n):
    if a[i] in a_dic.keys():
        a_dic[a[i]] += 1
    else:
        a_dic[a[i]] = 1

lis = sorted(list(a_dic.values()))
res = 0
if k >= len(lis):
    print(res)
else:
    for i in range(len(lis)-k):
        res += lis[i]
    print(res)

Solution (Python):

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

c = collections.Counter(A)
c.most_common()
values, counts = zip(*c.most_common())
L = list(counts)
L.sort()

ans = 0

for i in range(len(c)-K):
    ans += L[i]

if len(c) <= K:
    print(0)
else:
    print(ans)

Solution (Python):
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = collections.Counter(A)
c = sorted(c.values())
print(sum(c[:len(c)-K]))

Solution (Python):
from collections import Counter

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

ans = 0
S = sorted(S.items(), key=lambda x: x[1])
for i in range(len(S)-K):
    ans += S[i][1]
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    from collections import Counter
    C=Counter(map(int,input().split()))
    l=len(C)
    if l<=k:
        print(0)
        return
    v=sorted(list(C.values()))
    print(sum(v[:l-k]))
resolve()

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
v = list(sorted(A.values(),reverse=True))
print(sum(v[K:]))

Solution (Python):
import collections

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

A = collections.Counter(A)
A = A.most_common()

M = len(A) 
ans = 0

for i in range(len(A)-1, -1, -1):
    if M <= K:
        print(ans)
        break
    else:
        M -= 1
        ans += A[i][1]
else:
    print(ans)

Solution (Python):
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))

Solution (Python):
N, K = map(int, input().split())
array = list(map(int, input().split()))
dic = {}
ans = 0
for item in array:
    if item in dic:
        dic[item] += 1
    else:
        dic[item] = 1
dic_sorted = sorted(dic.items(), key=lambda x:x[1])
count = len(dic)
i = 0
while K < count:
    count -= 1
    ans += dic_sorted[i][1]
    i += 1
print(ans)

Solution (Python):

from collections import Counter


def main():
    N, K, *A = open(0).read().split()
    C, K = list(Counter(A).values()), int(K)
    C.sort(reverse=1)
    ans = sum(C[K:])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    N, K, *A = map(int, open(0).read().split())
    C = list(Counter(A).values())
    C.sort(reverse=1)
    ans = sum(C[K:])
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = set(a)
c = []
x = 1
ans = 0

if(len(b) > k):
    for i in range(1,n):
        if(a[i]!=a[i-1]):
            c.append(x)
            x = 1
        else:
            x += 1
    c.append(x)
    c.sort()
    for i in range(len(b) - k):
        ans += c[i]
        
print(ans)

Solution (Python):
N, K = [int(nk) for nk in input().split()]
A = [int(a) for a in input().split()]

A_set = list(set(A))
if len(A_set) <= K:
  print(0)
else: 
  dictionary = {}
  for n in A_set:
    dictionary[n] = 0
  for m in A:
    dictionary[m] += 1
  
  dict_val = list(dictionary.values())
  dict_val.sort(reverse = True)
  ans = N - sum(dict_val[:K])
  print(ans)

Solution (Python):
from collections import Counter

N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
nums = sorted(A.values(), reverse= True)
num = len(nums)
ans = 0

while num > K:
  ans += nums[-1]
  del nums[-1]
  num -= 1
print(ans)

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

l = [0] * (N + 1)
for i in range(N):
    l[A[i]] += 1
l.sort(reverse=True)
a = N - sum(l[:K])
print(a)

Solution (Python):
import collections
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
c = collections.Counter(a)
values, counts = zip(*c.most_common(k))
res = n - sum(counts) 
print(res if res >=0 else 0)

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

from collections import Counter

ac = Counter(A)
cnt = 0

if len(ac) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
        
print(cnt)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = Counter(list(map(int, input().split())))
L = max(0, len(A.keys()) - K)

print(sum(sorted(A.values())[:L]))

Solution (Python):
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a_list=list(map(int,input().split()))
b=[0]*n
for i in a_list:
    b[i-1]+=1
b.sort()
ans=0
for i in range(n-k):
    ans+=b[i]
print(ans)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0

ball = []

for i in c:
    ball.append(c[i])

ball.sort(reverse=True)
print(sum(ball[K:]))

Solution (Python):
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
a.append(0)
x=[]
t=a[0]
c=1
for i in range(1,n+1):
  if a[i]!=t:
    x.append(c)
    c=1
    t=a[i]
  else:
    c+=1
x.sort()
z=0
for i in range(len(x)-k):
  z+=x[i]
print(z)

Solution (Python):
from collections import Counter

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

Solution (Python):
from collections import Counter

n,k=map(int,input().split())
a=input().split()
x=len(list(set(a)))
n=x-k if x-k>=0 else 0

counter=Counter(a)
l=sorted(counter.values())
print(sum(l[:n]))

Solution (Python):
from collections import Counter
N,K = map(int, input().strip().split(' '))
counter_A = Counter(list(map(int, input().strip().split(' '))))
print(N-sum([v for k,v in counter_A.most_common(K)]))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    from collections import defaultdict
    B = defaultdict(int)
    for i in A:
        B[i] += 1
    C = []
    for i in B:
        C.append(B[i])
    C = sorted(C)
    if len(C) <= K:
        ans = 0
    else:
        ans = 0
        for i in range(len(C)-K):
            ans += C[i]
    print(ans)
    
    
main()

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
S=Counter(list(map(int,input().split()))).most_common()
if len(S)<=k:
  print(0)
else:
  print(sum(i[1] for i in S[k:]))

Solution (Python):
def main():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))

  l = [0] * (N+1)
  for i in range(N):
    l[A[i]] += 1
  l.sort(reverse=True)
  ans = N - sum(l[:K])
  print(ans)

if __name__ == '__main__':
  main()

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

l = [0] * (N+1)
for i in range(N):
    l[A[i]] += 1
l.sort(reverse=True)
ans = N - sum(l[:K])
print(ans)

Solution (Python):
import numpy as np
import collections

N,K = map(int, input().split())
As = input().split()
for i in range(N):
  As[i] = int(As[i])
As = np.array(As)

As_c = collections.Counter(As)

ans = 0
counter = 0
for a in sorted(As_c.values()):
  if counter < len(As_c) - K:
    ans += a 
    counter += 1
  else:
    break
print(int(ans))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
U=len(set(A))

import collections

if U > K:
  c = collections.Counter(A)
  d = c.most_common(K)
  print(N-(sum(x[1] for x in d)))
else:
  print(0)

Solution (Python):
from collections import Counter

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

c = Counter(As)

common = c.most_common(k)


common_sum = sum([item[1] for item in common])
print(n - common_sum)

Solution (Python):
from collections import Counter

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

c = Counter(As)
common = c.most_common(K)

common_sum = sum([item[1] for item in common])

print(N-common_sum)

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

a = sorted(a)
count = [0] * n
for i in range(n):
    count[a[i] - 1] += 1
index = sorted(range(len(count)), key=lambda j: count[j], reverse=True)
ans = 0
for i in range(k):
    ans += count[index[i]]
ans = sum(count) - ans
print(ans)

Solution (Python):
n, k = map(int, input().split())

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

a = {}

for i in a_input:
  if i in a:
    a[i] += 1
  else:
    a.setdefault(i, 1)
    
need_changes = len(a) - k

a = sorted(a.items(), key=lambda x:x[1])
a_values = [a[i][1] for i in range(len(a))]

count = 0
ans = 0
if need_changes > 0:
  for i in a_values:
    ans += i
    count += 1
    if count == need_changes:
      break
      
print(ans)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
A=list(map(int,input().split()))
s=len(set(A))
C=Counter(A).most_common()
if s>k:
	for i in range(k):
		n-=C[i][1]
	print(n)
else:
	print(0)

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

from collections import Counter

c = Counter(a)
d = c.most_common()

if len(d) <= k:
    print(0)

else:
    ans = 0
    while len(d) > k:
        item = d.pop()
        ans += item[1]
    print(ans)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
arr = map(int, input().split())
c = Counter(arr)
a = 0
l = len(c.keys()) - k
if 0 < l:
    for _, v in sorted(c.items(), key=lambda x: x[1])[:l]:
        a += v
print(a)

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

from collections import Counter

ac = Counter(A)

cnt = 0

if len(ac) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
    
print(cnt)

Solution (Python):
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    d = {}
    for Ai in A:
        if Ai in d.keys():
            d[Ai] += 1
        else:
            d[Ai] = 1
    
    
    
    kosuu = [item[1] for item in d.items()]
    kosuu.sort()
    shuruisuu = len(kosuu)
    
    ans = 0
    cnt = 0
    while K < shuruisuu:
        ans += kosuu[cnt]
        shuruisuu -= 1
        cnt += 1
    
    print(ans)

Solution (Python):
import sys
import math
from fractions import gcd

from collections import Counter



def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N , K =  map(int, sys.stdin.readline().split())
L =  list(map(int, sys.stdin.readline().split()))

C = Counter(L)
X = [x for x in C.items()]

X.sort(key=lambda x : x[1])

kind = len(X)
cnt = 0
idx = 0
while True:
    if kind <= K:
        print(cnt)
        exit()
    kind -= 1
    cnt += X[idx][1]
    idx += 1

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
D=sorted(d.items(), key=lambda x:x[1], reverse=True)
if len(set(A))>k:
    for i in range(k):
        n-=D[i][1]
    print(n)
else:
    print(0)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
a=Counter([int(i) for i in input().split()])
a=sorted(a.items(),key=lambda x:x[1])

li=[]
for i,j in a:
    li.append(j)

ans=0
if k>=len(a):
    ans=0
else:
    for i in range(len(a)-k):
        ans+=li[i]
print(ans)

Solution (Python):
import collections

N, K = map(int,input().split())
A = list(map(int,input().split()))
B = collections.Counter(A)
flag = 0
ans = 0
for b in B.most_common()[::-1]:
    if flag == max(0, len(B)-K):
        break
    ans += b[1]
    flag += 1
print(ans)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

c = list(Counter(A).values())
c.sort()

ret = 0
for i in range(len(c)-K) :
    ret += c[i]
print(ret)

Solution (Python):
import sys
import math
from fractions import gcd





def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N,K = map(int, sys.stdin.readline().split())
list_num = list(map(int, sys.stdin.readline().split()))
list_tmp = [0] * N


for num in list_num:
    
    list_tmp[num-1] += 1



list_tmp2 = [i for i in list_tmp if i > 0]

if(len(list_tmp2) <= K):
    print(0)
else:
    list_tmp2.sort()
    
    cnt = 0
    for i in range(len(list_tmp2) - K):
        cnt += list_tmp2[i]
    print(cnt)

Solution (Python):
from collections import*;_,k,*a=map(int,open(0).read().split());c=sorted(Counter(a).values());print(sum(c[:-min(len(c),k)]))

Solution (Python):

import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, K = map(int, input().split())
        A = map(int, input().split())
        A_c = collections.Counter(A)

        ans = 0
        for i, c in enumerate(A_c.most_common()[::-1]):
            if len(A_c) - i <= K:
                break
            else:
                ans += c[1]
        print(ans)



if __name__ == '__main__':
    AtCoder().main()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    dic = {}
    for t in a:
        if t in dic:
            dic[t] += 1
        else:
            dic[t] = 1
    dic = sorted(dic.items(), key=lambda x: -x[1])
    
    if len(dic) > K:
        ans = 0
        for i in range(K, len(dic)):
            ans += dic[i][1]
        print(ans)
    else:
        print(0)



if __name__ == "__main__":
    main()

Solution (Python):
from collections import*
n,k=[int(i) for i in input().split()]
l=input().split()
a=Counter(l)
ca=a.most_common()
val=len(set(l))
s=0
if val < k:
	k=val
for i in range(k):
	s +=ca[i][1]
print(n-s)

Solution (Python):
from collections import*
n,k=[int(i) for i in input().split()]
l=input().split()
a=Counter(l)
ca=a.most_common()
val=len(set(l))
s=0
if val < k:
	k=val
for i in range(k):
	s +=ca[i][1]
print(n-s)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
A=sorted(Counter(list(map(int,input().split()))).most_common(),key=lambda x:x[1],reverse=True)
print(n-sum([A[i][1] for i in range(min(k,len(A)))]))

Solution (Python):
N, K = [int(_) for _ in input().split()]

A = [int(_) for _ in input().split()]
from collections import Counter

counter = Counter(A)
vals = sorted(counter.values())

ans = 0
for i in range(0, len(set(A)) - K):
    ans += vals[i]

print(ans)

Solution (Python):
N, K = map(int, input().split())
A = input().split()
D = {}

for i in range(N):
	if A[i] in D.keys():
		D[A[i]] += 1
	else:
		D[A[i]] = 1

ans = 0
if len(D) > K:
	D = sorted(D.values(),reverse = True)
	ans = sum(D[K:])

print(ans)

Solution (Python):
N, K = map(int, input().split())
A = input().split()
D = {}

for i in range(N):
	if A[i] in D.keys():
		D[A[i]] += 1
	else:
		D[A[i]] = 1

ans = 0
if len(D) > K:
	D = sorted(D.values())
	for i in range(len(D) - K):
		ans += D[i]

print(ans)

Solution (Python):
import collections
N, K = map(int, input().split())
a = list(map(int,input().split()))
def v_c(l):
    values, counts = zip(*c.most_common())
    return values, counts
c = collections.Counter(a)
ans = 0
if len(c) > K:
    dif = len(c) - K
    values, counts = zip(*c.most_common())
    for i in range(len(c)-dif, len(c)):
        ans += counts[i]
print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = [0] * (N + 1)
for i in range(N):
    C[A[i]] += 1
A_sort = sorted(C, reverse=True)

print(sum(A_sort[K:]))

Solution (Python):
from collections import defaultdict


def resolve():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1

    if len(d) <= k:
        print("0")
    else:
        dd = sorted(d.values())
        ans = sum([v for v in dd[:len(d) - k]])
        print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


from collections import Counter

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


remain = len(set(A))-K


c = Counter(A)
c = c.most_common()[::-1]


count = 0
s = c[0:remain]

for _, num in s:
    count += num

print(count)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N,K = II()
A = III()

x = defaultdict(int)

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

num = len(x.keys())

if num<=K:
    print(0)
else:
    x2 = list(x.values())
    x2.sort()
    n = num-K
    ans = 0
    for i in range(n):
        ans += x2[i]
    print(ans)

Solution (Python):
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, k = na()
aaa = na()
c = Counter(aaa)
if len(c.keys()) <= k:
    print(0)
else:
    vvv = sorted(c.values())
    print(sum(vvv[:-k]))

Solution (Python):


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

c = collections.Counter(a_list)


c_list = sorted([v for k, v in c.items()])
ans = sum(c_list[:-K])
print(ans)

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

tmp = [0] * N

for i in A:
    tmp[i-1] += 1

tmp = sorted(tmp)

print(sum(tmp[0:N-K]))

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

num = len(set(a))
ans = 0

if num <= k:
    print(ans)
    exit()
else:
    dict_a = {}
    for i in a:
        if i not in dict_a:
            dict_a[i] = 1
        else:
            dict_a[i] += 1
    a_values = [v for v in dict_a.values()]
    a_values.sort()
    i = 0
    while num > k:
        ans += a_values[i]
        num -= 1
        i += 1

print(ans)

Solution (Python):
n, k = map(int, input().split())
alist = list(map(int, input().split()))
d = {}
for a in alist:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
print(sum(list(sorted(d[k] for k in d))[:-k]))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = [0]* (n+1)
for i in range(n):
    cnt[a[i]] += 1
list.sort(cnt,reverse=True)
print(sum(cnt[k:]))

Solution (Python):

n, k = map(int, input().split())
arr = list(map(int, input().split()))
d = {}
for a in arr:
  if a not in d:
    d[a] = 1
  else:
    d[a] += 1

t = len(d)

d = list(sorted(d.items(), key = lambda x : x[1]))
if t <= k:
  print(0)
else:
  count = 0
  for di in d[:t-k]:
    count += di[1]
  print(count)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
a = LI()
c = list(Counter(a).items())
c.sort(key = itemgetter(1))
m = len(c)
ans = 0
for i,j in c[:m-k]:
    ans += j
print(ans)