CodeEff/ECCO huggingface dataset:
# Original solution
import collections

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

number = len(set(A))

c = collections.Counter(A)
values,counts=list(zip(*c.most_common()))
count = 0
for i in range(number):
    if number <= K:
        print(count)
        break
    count += counts[-(i+1)]
    number -= 1

# Optimized solution
from collections import Counter

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

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

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

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

A_dict = {}
for i in A_set:
    A_dict[i] = A.count(i)
A_dict = sorted(list(A_dict.items()), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)


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

A_dict = {x:0 for x in A_set}
for i in A:
    A_dict[i] += 1
A_dict = sorted(list(A_dict.items()), key=lambda x:x[1])

ans = 0
if len(A_set) > K:
    for i in range(len(A_set) - K):
        ans += A_dict[i][1]
        
print(ans)
# Original solution
import collections
from collections import OrderedDict
count=0
N,K=list(map(int,input().split()))
ball=list(map(str,input().split()))
c=sorted(collections.Counter(ball).values())
n=len(c)-K
if n==0:
    print(count)
else:
    for i in range(n):
        count+=c[i]
    print(count)

# Optimized solution
import collections
N,K=list(map(int,input().split()))
c=sorted(collections.Counter(list(map(str,input().split()))).values())
print((sum(c[:-K])))
# Original solution
N, K = list(map(int, input().split()))
list_A = [int(x) for x in input().split()]

set_A = set(list_A)
if len(set_A) <= K :
    print((0))
    exit()

dict_A = dict.fromkeys(set_A, 0)

for i in range(N) :
    dict_A[list_A[i]] += 1

ans = 0

for i in range(len(set_A)-K) :
    ans += min(dict_A.values())
    del dict_A[min(dict_A, key=dict_A.get)]

print(ans)


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

list_num = [0 for i in range(N+1)]
for i in range(N) :
    list_num[list_A[i]] += 1

list_num.sort(reverse = True)

ans = N
for i in range(K) :
    ans -= list_num[i]

if ans > 0 :
    print(ans)
else :
    print((0))
# Original solution
import collections

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

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

cnt = 0
if n - K > 0:
    for i in range(n - K):
        cnt += c.most_common()[::-1][i][1]
print(cnt)

# Optimized solution
import collections

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

c = collections.Counter(A)
n = len(c)
c_sorted = sorted(c.values())
cnt = 0
for i in range(max(0, n - K)):
    cnt += c_sorted[i]
print(cnt)
# Original solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))

Ad = {x:0 for x in set(A)}
if len(set(A)) <= K:
    print((0))
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(list(Ad.items()), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)

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

if len(set(A))<=k:
    print((0))
else:
    d = {i:0 for i in set(A)}
    for a in A:
        d[a] += 1
    ans = list(d.values())
    ans.sort(reverse = True)
    print((sum(ans[k:])))
# Original solution
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))

if len(set(A))<=k:
    print((0))
else:
    d = {i:0 for i in set(A)}
    for a in A:
        d[a] += 1
    ans = list(d.values())
    ans.sort(reverse = True)
    print((sum(ans[k:])))

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

d = {i:0 for i in set(A)}
for a in A:
    d[a] += 1
ans = list(d.values())
ans.sort(reverse = True)
print((sum(ans[k:])))
# Original solution
import collections
N,K=list(map(int,input().split()))
li=list(map(int,input().split()))
li_count=collections.Counter(li)
change=0
S=max(len(li_count)-K,0)
for s in range(S):
    change+=li_count.most_common()[-1-s][1]
print(change)


# Optimized solution
import collections
N,K=list(map(int,input().split()))
li=list(map(int,input().split()))
li_count=collections.Counter(li)
li_count_most=li_count.most_common()[::-1]
change=0
S=max(len(li_count)-K,0)
for s in range(S):
    change+=li_count_most[s][1]
print(change)
# Original solution
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n, k = list(map(int, input().split()))
    a_list = list(input().split())
    a_set = set(a_list)

    c = Counter(a_list)

    cnt = 0
    for i in range(len(a_set) - k):
        cnt += c.most_common()[::-1][i][1]

    print(cnt)

if __name__ == '__main__':
    main()

# Optimized solution
#-*-coding:utf-8-*-
#from collections import Counter

def main():
    n, k = list(map(int, input().split()))
    a_list = list(input().split())
    a_set = set(a_list)

    #c = Counter(a_list)
    dic = {}
    for i in a_list:
        dic.setdefault(i, 0)
        dic[i] += 1

    freq = sorted(dic.values())

    cnt = 0
    for i in range(len(a_set) - k):
        cnt += freq[i]
        #cnt += c.most_common()[::-1][i][1]

    print(cnt)

if __name__ == '__main__':
    main()
# Original solution
from collections import Counter
N,K = list(map(int,input().split()))
src = list(map(int,input().split()))
ctr = Counter(src)

ans = 0
kind = len(ctr)
for k,v in reversed(ctr.most_common()):
    if kind <= K:
        break
    ans += v
    kind -= 1
print(ans)


# Optimized solution
from collections import Counter
N,K = list(map(int,input().split()))
src = list(map(int,input().split()))
ctr = Counter(src)

ans = N
for k,v in ctr.most_common(K):
    ans -= v
print(ans)
# Original solution
from collections import Counter
N,K = list(map(int,input().split()))
src = list(map(int,input().split()))
ctr = Counter(src)

ans = N
for k,v in ctr.most_common(K):
    ans -= v
print(ans)

# Optimized solution
from collections import Counter
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
ctr = Counter(A)
stay = 0
for k,v in ctr.most_common(K):
    stay += v
print((N - stay))
# Original solution
import collections
def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    c = collections.Counter(A)

    i = 0
    ans = 0
    for num, cnt in c.most_common()[::-1]:
        if i >= len(set(A)) - K:
            break
        ans += cnt
        i += 1

    print(ans)

main()

# Optimized solution
import collections
def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    TMP = [0] * N

    for i in A:
        TMP[i-1] += 1
    
    sort_TMP = sorted(TMP, reverse=True)
    max_ball = 0
    cnt = 1

    for a in sort_TMP:
        if cnt <= K:
            cnt += 1
            max_ball += a
        else:
            break
    
    print((N-max_ball))


main()
# Original solution
n, k = list(map(int, input().split()))
aList = list(map(int, input().split()))
num = [0 for _ in range(n + 1)]
for i in range(n + 1):
    if i in aList:
        num[i] += aList.count(i)
num.sort()
num = num[:-k]
print((sum(num)))


# Optimized solution
n, k = list(map(int, input().split()))
aList = list(map(int, input().split()))
num = [0 for _ in range(n + 1)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print((sum(num)))
# Original solution
from collections import Counter
N, K = list(map(int, input().split()))
A = Counter(list(map(int, input().split()))).most_common()
l = len(A)
ans = 0
while l > K:
	ans += A[-1][1]
	del A[-1]
	l = len(A)
print(ans)


# Optimized solution
from collections import Counter
N, K = list(map(int, input().split()))
A = Counter(list(map(int, input().split()))).most_common()
ans = 0
while len(A) > K:
	ans += A[-1][1]
	del A[-1]
print(ans)
# Original solution
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(n, k, a_lst):
    # implement process
    a_set = set(a_lst)
    ak = len(a_set)
    diff = ak - k
    if diff < 1:
        return 0
    
    min_change = float("inf")
    cnt_lst = []
    for a in a_set:
        cnt_lst.append(a_lst.count(a))
    cnt_lst.sort()
    return sum(cnt_lst[0:diff])

def main():
    # input
    n, k = list(map(int,input().split()))
    a_lst = list(map(int,input().split()))

    # process
    ans = str( solve(n, k, a_lst) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
10 3
5 1 3 2 4 1 1 2 3 4
"""
_EXPECTED = """\
0
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

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

import io
import sys
import math

def solve(n, k, a_lst):
    # implement process
    a_set = set(a_lst)
    ak = len(a_set)
    diff = ak - k
    if diff < 1:
        return 0
    
    #ソート済み配列を検査することで、count処理を線形にする
    a_lst.sort()
    tmp = a_lst[0]
    cnt = 0
    cnt_lst = []
    for i in range(len(a_lst)):
        if tmp != a_lst[i]:
            tmp = a_lst[i]
            cnt_lst.append(cnt)
            cnt = 0
        cnt += 1
    cnt_lst.append(cnt)
    cnt_lst.sort()
    return sum(cnt_lst[0:diff])

def main():
    # input
    n, k = list(map(int,input().split()))
    a_lst = list(map(int,input().split()))

    # process
    ans = str( solve(n, k, a_lst) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
5 2
1 1 2 2 5
"""
_EXPECTED = """\
0
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")
# Original solution
import collections

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

c = collections.Counter(a)
count = 0

for i in range(k, len(c)):
        count += c.most_common()[i][1]

print(count)

# Optimized solution
n, k = list(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)
# Original solution
n,k = list(map(int,input().split()))
a = {}
s = 0
for i in input().split():
    a[int(i)] = a.get(int(i),0)+1
b = list(a.values())
while(k<len(b)):
    c = min(b)
    s+=c
    b.remove(c)
print(s)

# Optimized solution
n,k = list(map(int,input().split()))
a = {}
for i in input().split():
    a[int(i)] = a.get(int(i),0)+1
b = list(a.values())
b.sort()
print((sum(b[:len(b)-k])))
# Original solution
# -*- coding: utf-8 -*-

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

dict_A = {}
for a in A:
    if a not in dict_A:
        dict_A[a] = 1
    else:
        dict_A[a] += 1

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

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

ans = 0
for i in range(len(list(dict_A.keys()))-k):
    ans += sorted_A[i][1]

print(ans)


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

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

B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1

C = sorted(list(B.items()), key=lambda x: x[1])
if len(C) <= k:
    print((0))
else:
    ans = 0
    for i in range(len(C)-k):
        ans += C[i][1]
    print(ans)
# Original solution
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print((0))


# Optimized solution
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print((0))
# Original solution
N, K = [int(x) for x in input().split(" ")]
lst = [int(x) for x in input().split(" ")]

dic= {}
cnt = 0 
swap = 0

for i in range(1,N+1):
	dic["{}".format(i)] = 0

for i in range(0,N):
	dic["{}".format(lst[i])] += 1

sorted_dic = sorted(list(dic.items()), key = lambda x : x[1])
    
for i in range(0,N):
  swap += sorted_dic[i][1]
  if sorted_dic[i][1] != 0:
    cnt +=1
  if cnt >= len(set(lst))-K:
    break
      
print(swap)

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

dic= {}
cnt = 0 
swap = 0
prep = len(set(lst))-K

for i in range(1,N+1):
	dic["{}".format(i)] = 0

for i in range(0,N):
	dic["{}".format(lst[i])] += 1

sorted_dic = sorted(list(dic.items()), key = lambda x : x[1])
    
for i in range(0,N):
  swap += sorted_dic[i][1]
  if sorted_dic[i][1] != 0:
    cnt +=1
  if cnt >= prep:
    break
      
print(swap)
# Original solution
from collections import Counter

from sys import stdin

input = stdin.readline

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

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


def main():
    # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ
    # 先頭 K + 1 個目から 末尾 まで
    # 要素数(v) 合計
    print((sum([v for k, v in An.most_common()[K:]])))

    return


main()


# Optimized solution
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter(input().split())


def main():
    # 要素数(v) 昇順
    # 先頭 から インデックス len(An) - K - 1 まで
    # 要素数(v) 合計
    print((sum(sorted(An.values())[:len(An) - K])))

    return


main()
# Original solution
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter(input().split())


def main():
    # 要素数(v) 昇順
    # 先頭 から インデックス len(An) - K - 1 まで
    # 要素数(v) 合計
    print((sum(sorted(An.values())[:len(An) - K])))

    return


main()


# Optimized solution
from collections import Counter

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

An = Counter(input().split())


def main():
    # 要素数(v) 昇順
    # 先頭 から インデックス len(An) - K - 1 まで
    # 要素数(v) 合計
    print((sum(sorted(An.values())[:len(An) - K])))

    return


main()
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

count = [0] * n

for x in range(n):
    count[a[x]-1] += 1

count.sort()
length = len(count)

for x in range(length):
    if len(count[x:]) == k:
        break

print((sum(count[:x])))


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

count = [0] * n

for x in range(n):
    count[a[x]-1] += 1

count.sort()
length = len(count)

print((sum(count[:length - k])))
# Original solution
import collections
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
sum = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
for i in range(K,tmp,1):
    sum += li.most_common()[i][1]
print(sum)

# Optimized solution
import collections
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
ans = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
value,counts = list(zip(*li.most_common()))
for i in range(K,tmp,1):
    ans += counts[i]
print(ans)
# Original solution
from collections import Counter
n, k = list(map(int, input().split()))
a = Counter((i for i in input().split()))

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

total = 0
while len(sort_count) > k:
    _, n = sort_count.pop(0)
    total += n

print(total)


# Optimized solution
from collections import Counter


n, k = list(map(int, input().split()))
a = Counter((i for i in input().split()))

sort_count = sorted(a.values())


total = 0
l = len(sort_count)

if len(sort_count) <= k:
    print((0))
else:
    print((sum(sort_count[:l-k])))
# Original solution
from collections import defaultdict
n, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print((sum(sorted(d.values())[:-k])))

# Optimized solution
from collections import defaultdict
n, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print((sum(sorted(list(d.values()), reverse=True)[k:])))
# Original solution
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
def judge(n, k, nums):
  original = nums
  types = set(nums)
  diff = len(types) - k
  count = []
  ans = 0

  if len(types) <= k:
    return 0

  for i in types:
    count.append(original.count(i))
  count.sort()

  for i in range(diff):
    ans += count[i]
  
  return ans

print((judge(n, k, nums)))

# Optimized solution
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))
def judge(n, k, nums):
  original = nums
  types = set(nums)
  diff = len(types) - k
  count = []
  temp_count = 0
  temp_char = nums[0]
  ans = 0
  nums.sort()

  if len(types) <= k:
    return 0

  for i in range(n):
    if nums[i] == temp_char:
      temp_count += 1
    else:
      temp_char = nums[i]
      if not temp_count == 0:
        count.append(temp_count)
      temp_count = 1

    if i == n-1:
      if not temp_count == 0:
        count.append(temp_count)
        
  count.sort()
  
  return sum(count[:diff])

print((judge(n, k, nums)))
# Original solution
n, k  = list(map(int, input().split()))
a = list(map(int, input().split()))

a = sorted(a)
p = list(set(a))

if len(p) <= k:
    print('0')
    exit()

j = 0
ans = [0 for _ in range(len(p))]
for i in range(len(p)):
    ans[i] += a.count(p[i])

ans = sorted(ans)

print((sum(ans[:len(p) - k])))

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

a = sorted(a)
p = list(set(a))

if len(p) <= k:
    print('0')
    exit()

j = 0
ans = [0 for _ in range(len(p))]
ans[0] = 1
for i in range(1, n):
    if a[i] == a[i - 1]:
        ans[j] += 1
    else:
        j += 1
        ans[j] += 1

ans = sorted(ans)

print((sum(ans[:len(p) - k])))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

import collections

c = collections.Counter(A)
values, counts = list(zip(*c.most_common()[::-1]))
counts = list(counts)
cnt = 0
inf = 10 ** 18


for _ in range(inf):
  if len(counts) <= K:
    print(cnt)
    break

  cnt +=  counts[0]  
  counts = counts[1:]
    


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

import collections
from itertools import accumulate

c = collections.Counter(A)
_, counts = list(zip(*c.most_common()[::-1]))
counts = list(accumulate(counts))
cnt = 0
inf = 10 ** 18

target = len(counts) - K 
 
if target <= 0:
  print((0))
else:
  print((counts[target-1]))
# Original solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = set(a)
r = []
for i in s:
	r.append(a.count(i))
r = sorted(r)
dif = len(s) - k
print((sum(r[0:max(0,dif)])))

# Optimized solution
import itertools
n,k = list(map(int,input().split()))
a = sorted(list(map(int,input().split())))
c = []
g = itertools.groupby(a)
for m,v in g:
    c.append(len(list(v)))
c = sorted(c)
print((sum(c[:-k])))
# Original solution
N, K = [int(i) for i in input().split()]
B = sorted([int(i) for i in input().split()])
D ={}
bag = 0

for i in B:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1

LLL = sorted(list(D.values()))
AA = len(D) - K
if len(D) <= K:
    print((0))
else:
    for i in range(AA):
        bag += LLL[i]
    print(bag)

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

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

dic_sort = sorted(list(dic.items()), key=lambda x:x[1], reverse=True)

ans = []
for i in range(K, len(dic_sort)):
    ans.append(dic_sort[i][1])

print((sum(ans)))
# Original solution
from collections import Counter
from collections import defaultdict
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = Counter(A).most_common()
dict = []
for l in B:
    dict.append([l[0], l[1]])
dict.sort(key=lambda x:x[1])
count = 0
l = len(B)
if l <= K:
    print((0))
else:
    while l != K:
        count += dict[0][1]
        del dict[0]
        dict.sort(key=lambda x:x[1])
        l = len(dict)
        if l == K:
            break
    print(count)


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

ca = Counter(A)
ca = sorted(list(ca.items()), key=lambda x:x[1], reverse=True)

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

print((N-ans))
# Original solution
import sys
import collections

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')

N, K = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]

count =	0
while len(set(nums)) > K:
	c = collections.Counter(nums)
	ma = c.most_common()[0]
	mi = c.most_common()[-1]

	nums = [ma[0] if i == mi[0] else i for i in nums]
	count += mi[1]
print(count)

# Optimized solution
import sys
import collections

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')

N, K = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]

c = collections.Counter(nums)
d = c.most_common()[::-1]
print((sum([d[i][1] for i in range(len(d) - K)])))
# Original solution
N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
s=[0 for i in range(200000)]
for i in range(200000):
    t=A.count(i)
    s[i]+=t
s.sort()
s.reverse()
p=0
for i in range(K):
    p+=s[i]
print((N-p))

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

dic = {}
for num in a:
    if num not in list(dic.keys()):
        dic[num] = 0
    dic[num] += 1

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

ans = 0

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

print(ans)

# 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

b.sort(reverse=True)

ans = 0

for i in range(k):
    ans +=b[i] 

if n - ans <= 0:
    print((0))
else:
    print((n - ans))
# Original solution
from collections import Counter

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

cnt_lst = Counter(n_lst).most_common()[k:]
ans = 0
for x in cnt_lst:
    ans += x[1]
print(ans)


# Optimized solution
n,k = list(map(int,input().split()))
n_lst = list(map(int,input().split())) 
cnt_lst = [0 for _ in range(n+1)]

for x in n_lst:
    cnt_lst[x] += 1
cnt_lst.sort(reverse=True)
print((sum(cnt_lst[k:])))
# Original solution
import collections

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

cnt = 0

for i in range(N):
    if len(A) > K:
        min_k = min(A, key=A.get)
        cnt += A[min_k]
        A.pop(min_k)
    else:
        break

print(cnt)


# Optimized solution
import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = dict(collections.Counter(A))
A = sorted(list(A.items()), key=lambda x: x[1], reverse=True)

cnt = 0

for i in range(N):
    if len(A) > K:
        cnt += A[-1][1]
        A.pop()
    else:
        break

print(cnt)