import collections

import sys

input = sys.stdin.readline



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

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

ans = 0

set_a = set(a)

count_a = collections.Counter(a).most_common()[::-1]

if len(set_a)-k > 0:

    for i in range(len(set_a)-k):

        ans += count_a[i][1]

print(ans)
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from collections import Counter



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

counter = sorted(Counter(a).values())

ans = 0

for i in range(len(counter) - k):

    ans += counter[i]

print(ans)

import collections
import sys

input = sys.stdin.readline
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
set_a = set(a)
count_a = collections.Counter(a).most_common()[::-1]
if len(set_a) - k > 0:
    for i in range(len(set_a) - k):
        ans += count_a[i][1]
print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import Counter

n, k, *a = list(map(int, read().split()))
counter = sorted(Counter(a).values())
ans = 0
for i in range(len(counter) - k):
    ans += counter[i]
print(ans)

-import collections -input = sys.stdin.readline -n, k = list(map(int, input().split())) -a = list(map(int, input().split())) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +sys.setrecursionlimit(10**7) +from collections import Counter + +n, k, *a = list(map(int, read().split())) +counter = sorted(Counter(a).values()) -set_a = set(a) -count_a = collections.Counter(a).most_common()[::-1] -if len(set_a) - k > 0: -    for i in range(len(set_a) - k): -        ans += count_a[i][1] +for i in range(len(counter) - k): +    ans += counter[i]