CodeEff/ECCO huggingface dataset:
# Original solution
from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
syurui = len(set(a))
#print(syurui)
c = Counter(a)
ans = 0
for i in range(1, syurui-k + 1):
    ans += c.most_common()[-i][1]
print(ans)

# Optimized solution
from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
syurui = len(set(a))
#print(syurui)
c = Counter(a)
ans = 0
c_sort = c.most_common()
#print(c_sort)
for i in range(1, syurui-k + 1):
    ans += c_sort[-i][1]
print(ans)
# Original solution
import sys
input = sys.stdin.readline
n,k = list(map(int,input().split()))

A = list(map(int,input().split()))
sum = 0
import collections

c = collections.Counter(A)
c = c.most_common()
while len(c) > k:
    sum += c[-1][1]
    c = c[:-1]
print(sum)

# Optimized solution
import sys
import collections
input = sys.stdin.readline
n,k = list(map(int,input().split()))

A = list(map(int,input().split()))
sum = 0
c = collections.Counter(A)
c = c.most_common()
if len(c) > k:
  a = len(c)-k
  c = c[-a:]
  for i in range(a):
    sum += c[i][1]
  print(sum)
else:
  print((0))
# Original solution
N , K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
cnt = []
while len(A) > 0:
    temp = A[0]
    i_cnt = 0
    while A[0] == temp:
        i_cnt += 1
        del A[0]
        if len(A) == 0:
            break
    cnt.append(i_cnt)
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)

# Optimized solution
N , K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
A.append(0)
cnt = []
i_cnt = 1
for i in range(N):
    if A[i] == A[i + 1]:
        i_cnt += 1
    else:
        cnt.append(i_cnt)
        i_cnt = 1
cnt.sort()
result = 0
for i in range(len(cnt) - K):
    result += cnt[i]
print(result)
# Original solution
import collections
import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = collections.Counter(a)
v = list(d.values())
v = sorted(v)
ans = 0

while len(v) > k:
    ans += v.pop(0)

print(ans)


# Optimized solution
import collections
import sys
input = sys.stdin.readline

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = collections.Counter(a)
v = list(d.values())
v = sorted(v)

ans = 0
i = 0
while len(v) - i > k:
    ans += v[i]
    i += 1

print(ans)
# Original solution
list_ = [0]
n, min_count = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
kind = 1
tmp = a[0]
for i in range(n):
    if(tmp != a[i]):
        kind += 1
        tmp = a[i]
        list_.append(0)
    list_[kind - 1] += 1
ans = 0
for i in range(kind - min_count):
    min_idx = list_.index(min(list_))
    ans += list_[min_idx]
    list_[min_idx] = 200001
print(ans)

# Optimized solution
list_ = [0]
n, min_count = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
kind = 1
tmp = a[0]
for i in range(n):
    if(tmp != a[i]):
        kind += 1
        tmp = a[i]
        list_.append(0)
    list_[kind - 1] += 1
ans = 0
list_.sort()
idx = 0
for i in range(kind - min_count):
    ans += list_[idx]
    idx += 1
print(ans)
# Original solution
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
for i in range(N):
    if li[i] == -1: 
        pass
    else:
        count = 0 
        num = li[i]
        for i2 in range(N - i): 
            if li[i + i2] == num:
                count += 1
                li[i + i2] = -1
        typ.append(count)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)

# Optimized solution
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
li.sort()
count = 0 
for i in range(N - 1): 
    count += 1
    if li[i] != li[i + 1]: 
        typ.append(count)
        count = 0 
if li[N - 1] != li[N - 2]: 
    typ.append(1)
else:
    typ.append(count + 1)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)
# Original solution
n,k = list(map(int,input().split()))

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

for i in a:
    if i not in freq:
        freq[i] = 1
    else:
        freq[i] += 1

total = 0
while len(list(freq.keys())) > k:
    mn = (0,2000001)
    for i in list(freq.keys()):
        if freq[i] < mn[1]:
            mn = (i,freq[i])
    total += mn[1]
    del freq[mn[0]]
print(total)


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

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

for i in a:
    if i not in freq:
        freq[i] = 1
    else:
        freq[i] += 1
        
l = sorted(freq.values())
total = 0
index = 0

while len(l) - index > k:
    total += l[index]
    index += 1
print(total)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

A_dict = {}
rewrite = 0

for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

while len(A_dict) > K:
    rewrite_key = min(A_dict, key=A_dict.get)
    rewrite += A_dict[rewrite_key]
    del A_dict[rewrite_key]

print(rewrite)


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

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

A_sorted = sorted(list(A_dict.items()), key=lambda x:x[1], reverse=True)
rewrite = 0
while len(A_sorted) > K:
    tmp = A_sorted.pop()
    rewrite += tmp[1]

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

## 種類数の求め方
# 1. A内の要素を取り出して、それがA内に存在するとき：種類＋１
# 2. その要素を重複数だけAから削除してループ

kinds = 0
A.sort()
duplicatedList = []
while len(A) > 0:
    if A[0] in A:
        kinds += 1
        duplicatedList.append(A.count(A[0]))
        for j in range(A.count(A[0])):
            A.remove(A[0])

if kinds <= K:
    print('0')
else:
    duplicatedList.sort()
    tmp = 0
    for i in range(kinds-K):
        tmp += duplicatedList[i]
    print(tmp)

# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=len(l)
        l.append(1)
ans=0
l.sort()
for i in range(len(l)-k):
    ans+=l[i]
print(ans)
# Original solution
import collections
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
hint = collections.Counter(A)
ans = 0
bb = hint.most_common()
if K >= len(bb):
    print(ans)
else:
    for i in range(-1, -(len(bb)-K)-1, -1):
        ans += bb[i][1]
    print(ans)

# Optimized solution
import collections

N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
ans = 0
con = collections.Counter(A).most_common()
if len(con) <= K:
    print(ans)
else:
    for a, b in con[K:]:
        ans += b
    print(ans)
# Original solution
import collections

N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]
ans = 0
con = collections.Counter(A).most_common()
if len(con) <= K:
    print(ans)
else:
    for a, b in con[K:]:
        ans += b
    print(ans)

# Optimized solution
import collections

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

num = collections.Counter(A).most_common()[::-1]
ans = 0

if len(num) > K:
    for i in range(len(num) - K):
        ans += num[i][1]
print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
Alist = []
setA = [x for x in set(a)]
for i in setA:
  Alist.append(a.count(i))
Alist.sort()
ans = 0
for i in range(len(Alist) - k):
  ans += Alist[i]
print(ans)

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

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

count = [0] * len(set(A))
labels = set(A)
for val in A:
    for i, label in enumerate(labels):
        if label==val:
            count[i] += 1

ans = 0
diff = len(set(A)) - K
if diff > 0:
    count_sorted = sorted(count)
    for i in range(diff):
        ans += count_sorted[i]

print(ans)

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

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

count = {}
for val in A:
    if val in count:
        count[val] += 1
    else:
        count[val] = 1

ans = 0
diff = len(set(A)) - K
if diff > 0:
    count_sorted = sorted(list(count.items()), key=lambda x:x[1])
    for k,v in count_sorted:
        ans += v
        diff -= 1
        if diff == 0:
            break

print(ans)
# Original solution
N, K = [int(x) for x in input().split()]
A_lst = [int(x) for x in input().split()]
dict = {}
for i in A_lst:
    if not i in list(dict.keys()):
        dict[i] = 1
    else:
        dict[i] += 1

lst = []
for i in list(dict.keys()):
    lst.append(dict[i])
lst.sort()
k = len(lst)
cnt = 0

for i in lst:
    if k <= K:
        break
    else:
        k -= 1
        cnt += i

print(cnt)


# Optimized solution
N, K = [int(x) for x in input().split()]
A_lst = [int(x) for x in input().split()]
dict = {}
for i in A_lst:
    if not i in list(dict.keys()):
        dict[i] = 1
    else:
        dict[i] += 1

val_lst = list(dict.values())
val_lst.sort()
k = len(val_lst)
cnt = 0

for i in val_lst:
    if k <= K:
        break
    else:
        k -= 1
        cnt += i

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

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

kinds = sorted(buckets.values())
count = len(kinds)
if K < count:
    mini = 0
    for i in kinds:
        mini += i
        count -= 1
        if count <= K:
            break
    print(mini)
else:
    print((0))

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

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

kinds = sorted(list(buckets.values()), reverse=True)
if K < len(kinds):
    mini = N-sum([kinds[i] for i in range(K)])
    print(mini)
else:
    print((0))
# Original solution
n,k = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
num_list = list(map(int,input().split()))
for tmp in num_list:
	d[tmp] += 1
    
v_list = sorted(list(d.values()))
while len(v_list) > k:
    v_list.pop(0)
print((n - sum(v_list)))

# Optimized solution
n,k = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
num_list = list(map(int,input().split()))
for tmp in num_list:
	d[tmp] += 1
    
v_list = sorted(list(d.values()) ,reverse=True)

print((n - sum(v_list[:k])))
# Original solution
N,K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
counter_list = []
for i in range(1,N+1):
    if a_list.count(i) > 0:
        counter_list.append(a_list.count(i))

counter_list.sort()

count = 0
for i in range(len(counter_list) - K):
    count += counter_list[i]

print(count)


# Optimized solution
N,K = list(map(int, input().split()))
a_list = list(map(int, input().split()))
counter_list = [0]*N
for i in a_list:
    counter_list[i-1] += 1

counter_list.sort(reverse=True)

ans = N - sum(counter_list[:K])    

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

d = dict()
for i in a:
    d[i] = d.get(i, 0) + 1
d_sorted = sorted(d.values())
knd = len(set(a))##種類数
print((sum(d_sorted[:knd - k])))    

# Optimized solution
n, k = list(map(int, input().split()))
a = input().split()
b = dict()
for i in a:
    b[i] = b.get(i, 0) + 1
print((sum(sorted(b.values())[:-k])))
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print((min(n*a,b)))
    return

#B
def B():
    s = S()
    print((s.count("1")))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return

#E
def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return

#F
def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    F()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    res = len(d)-k
    print((sum(d[:res])))
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
import collections

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

# Optimized solution
import collections

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = collections.Counter(a)
ans = 0
t=cnt.most_common()
if len(t) <= k:
    print((0))
    exit()

for i in range(k):
    ans += t[i][1]
print((n - ans))
# Original solution
# -*- coding: utf-8 -*-

from collections import Counter 

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

# 各数値ごとに数を集計
num_dict = Counter(num_list)

ans = 0
while True:
    # 種類数がK以下なら終了
    if len(num_dict) <= K:
        print(ans)
        exit()

    # 一番数が少ない要素の個数分、答えに追加
    ans += num_dict.most_common()[-1][1]
    # 一番数が少ない要素を削除
    del num_dict[num_dict.most_common()[-1][0]]

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

from collections import Counter 

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

# 各数値ごとに数を集計
num_dict = Counter(num_list)
# 数の少ない順でソート
num_tpl = num_dict.most_common()[::-1]

ans = 0
for i in range(len(num_tpl)):
    # 種類数がK以下なら終了
    if len(num_tpl) - i <= K:
        print(ans)
        exit()
    # 数が少ない要素から、答えに追加していく
    ans += num_tpl[i][1]
# Original solution
from collections import Counter
from collections import OrderedDict
N, K = list(map(int, input().split()))
cnt = Counter(list(map(int, input().split())))
tot = 0
if len(cnt) <= K:
    print((0))
else:
    k = []
    for i in list(cnt.values()):
        k.append(i)
    k.sort()
    for i in range(len(cnt)-K):
        tot += k[i]
    print(tot)


# Optimized solution
from collections import Counter
N, K = list(map(int, input().split()))
cnt = Counter(list(map(int, input().split())))
tot = 0
k = []
for i in list(cnt.values()):
    k.append(i)
k.sort()
for i in range(len(cnt)-K):
    tot += k[i]
print(tot)
# Original solution
import collections as col

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

L= len(set(A))
A = col.Counter(A)
ans = 0

if L <= K:
    print((0))
    
else:
    for i in range(1,L-K+1):
        ans += A.most_common()[-i][1]
    print(ans)

# Optimized solution
import collections as col

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

L= len(set(A))
A = col.Counter(A)

Aval = list(A.values())
Aval = sorted(Aval)

ans = 0

if L <= K:
    print((0))
    
else:
    for i in range(L-K):
        ans += Aval[i]
    print(ans)
# Original solution
import collections
import sys
N,K=list(map(int,input().split()))
a=[]
a=collections.Counter( list(map(int,input().split())) )
b=sorted(list(a.items()), key=lambda x:x[1])

if len(b)=="K":
	print(0)
	sys.exit()
else:
	sum=0
	for i in range(len(b)-K):
		sum+=b[i][1]
	else:
		print(sum)


# Optimized solution
import sys
from collections import Counter
N,K=list(map(int, sys.stdin.readline().split()))
A=list(map(int, sys.stdin.readline().split()))
C=Counter(A)
C=list(C.values())
C.sort()
print(sum(C[:-1*K]))
# Original solution
import collections

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

c = collections.Counter(A)

cnt = 0
if K < len(list(c.keys())):
    for i in range(1,abs(len(list(c.keys())) - K)+1):
            cnt += c.most_common()[-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)

cnt = 0
most_common = c.most_common()
if K < len(list(c.keys())):
    for i in range(1,abs(len(list(c.keys())) - K)+1):
            cnt += most_common[-i][1]
print(cnt)
# Original solution
import collections
N,K = list(map(int,input().split()))
a = list(map(int,input().split()))
c = collections.Counter(a)
if len(c) <= K:
    print((0))
else:
    print((sum([c.most_common()[-i][1] for i in range(1,len(c)-K+1)])))

# Optimized solution
import collections
N,K = list(map(int,input().split()))
a = list(map(int,input().split()))
c = collections.Counter(a)
c_most = c.most_common()
if len(c) <= K:
    print((0))
else:
    print((sum([c_most[-i][1] for i in range(1,len(c)-K+1)])))
# Original solution
import sys

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

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

num_flag = [0 for i in range(n)]

for item in a:
    num_flag[item - 1] += 1

while 0 in num_flag:
    num_flag.remove(0)

num_flag.sort()

cnt = 0
while len(num_flag) > k:
    cnt += num_flag[0]
    num_flag.pop(0)

print(("{}".format(cnt)))

# Optimized solution
import sys

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

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

num_flag = [0 for i in range(n)]

for item in a:
    num_flag[item - 1] += 1

# while 0 in num_flag:
#     num_flag.remove(0)

# num_flag.sort()

# cnt = 0
# while len(num_flag) > k:
#     print(len(num_flag))
#     cnt += num_flag[0]
#     num_flag.pop(0)

num_flag.sort(reverse=True)

cnt = 0
for i in range(k):
    cnt += num_flag[i]

print(("{}".format(n - cnt)))
# Original solution
N, K = list(map(int,input().split()))
ball = input().split()
ball_list = sorted(list(set(ball)))
nums = len(ball_list)

if K >= nums:
  print("0")
  exit()

balls = []
for i in range(nums):
  balls.append(ball.count(ball_list[i]))

balls = sorted(balls, reverse=True)
print((N - sum(balls[:K])))

# Optimized solution
N, K = list(map(int,input().split()))
ball = input().split()
d = {}

if K >= len(set(ball)):
  print("0")
  exit()

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

d_val = sorted(list(d.values()),reverse=True)
print((N - sum(d_val[:K])))
# Original solution
nk = list(map(int,input().split()))
ls = list(map(int,input().split()))

d = dict()

for i in ls:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
       
adj = 0
key_num = len(list(d.keys())) 

while(1):
    if key_num <= nk[1]:
        print(adj)
        break
    min_idx = min(list(d.items()), key=lambda x:x[1])[0]
    min_num = min(list(d.items()), key=lambda x:x[1])[1]
    del d[min_idx]
    adj += min_num
    key_num -= 1

# Optimized solution
nk = list(map(int,input().split()))
ls = list(map(int,input().split()))

d = dict()

for i in ls:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
       
l = list(d.values())
l.sort(reverse = True)

num = sum(l[nk[1]:])

print(num)
# Original solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = set(a)
syurui = []
ans = 0
for i in b:
    syurui.append(a.count(i))
syurui.sort()
if len(b) <= k:
    print((0))
else:
    for i in range(len(b)-k):
        ans += syurui[i]
    print(ans)


# Optimized solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
ans = 0
key = a[0]
a_syurui = []
count = 1
for i in a[1:]:
    if key == i:
        count += 1
    else:
        a_syurui.append(count)
        count = 1
        key = i
a_syurui.append(count)
a_syurui.sort()
if len(a_syurui) <= k:
    print((0))
else:
    for i in range(len(a_syurui)-k):
        ans += a_syurui[i]
    print(ans)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt_list = []
b = set(a)
for s in b:
    cnt_list.append(a.count(s))
cnt_list = sorted(cnt_list)

print((sum(cnt_list[:len(cnt_list) - k])))

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt_list = [0]*(n+1)
for i in range(n):
    cnt_list[a[i]] += 1
cnt_list.sort()
print((sum(cnt_list[:len(cnt_list) - k])))
# Original solution
import collections
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a_val = collections.Counter(a)
count = 0

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

print(count)

# Optimized solution
from collections import Counter
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(list(Counter(a).values()), reverse=True)

print((sum(a[k:])))
# Original solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
count_rmv = 0
count_int = sorted(collections.Counter(A).values())
num_int_type = len(count_int)

while num_int_type > K:
    count_rmv += count_int[0]
    del count_int[0]
    num_int_type -= 1

print(count_rmv)


# Optimized solution
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import collections

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

count_rmv = 0
count_int = collections.Counter(A).most_common()
num_int_type = len(count_int)

while num_int_type > K:
    num_int_type -= 1
    count_rmv += count_int[num_int_type][1]

print(count_rmv)
# Original solution
N,K = [int(i) for i in input().split()]
AAA = [int(i) for i in input().split()]

count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
while sum([1 if i!=0 else 0 for i in count])>K:
    #print(count[:10])
    buff = min([i for i in count if i!=0])
    ans += buff
    count.remove(buff)
print(ans)

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

count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
count=sorted([i for i in count if i!=0])

if len(count)<=K:
    print("0")
    exit()
else:
    print((sum(count[:-K])))