import sys

input = sys.stdin.readline

ins = lambda: input().rstrip()

ini = lambda: int(input().rstrip())

inm = lambda: map(int, input().split())

inl = lambda: list(map(int, input().split()))

out = lambda x: print('\n'.join(map(str, x)))



n, k = inm()

a = inl()

if len(set(a)) <= 2:

    print(0)

else:

    b = {}

    for i in a:

        if i not in b:

            b[i] = 0

        b[i] += 1

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

    ans = 0

    for i in range(len(set(a))-k):

        ans += b[i][1]

    print(ans)

import sys

input = sys.stdin.readline

ins = lambda: input().rstrip()

ini = lambda: int(input().rstrip())

inm = lambda: map(int, input().split())

inl = lambda: list(map(int, input().split()))

out = lambda x: print('\n'.join(map(str, x)))



n, k = inm()

a = inl()

if len(set(a)) <= 2:

    print(0)

else:

    b = {}

    for i in a:

        if i not in b:

            b[i] = 0

        b[i] += 1

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

    print(sum(b[:len(set(a))-k]))

import sys

input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print("\n".join(map(str, x)))
n, k = inm()
a = inl()
if len(set(a)) <= 2:
    print(0)
else:
    b = {}
    for i in a:
        if i not in b:
            b[i] = 0
        b[i] += 1
    b = sorted(b.items(), key=lambda x: x[1])
    ans = 0
    for i in range(len(set(a)) - k):
        ans += b[i][1]
    print(ans)

import sys

input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print("\n".join(map(str, x)))
n, k = inm()
a = inl()
if len(set(a)) <= 2:
    print(0)
else:
    b = {}
    for i in a:
        if i not in b:
            b[i] = 0
        b[i] += 1
    b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1])))
    print(sum(b[: len(set(a)) - k]))

-    b = sorted(b.items(), key=lambda x: x[1]) -    ans = 0 -    for i in range(len(set(a)) - k): -        ans += b[i][1] -    print(ans) +    b = list(map(lambda x: x[1], sorted(b.items(), key=lambda x: x[1]))) +    print(sum(b[: len(set(a)) - k]))