import collections





def calc(A, K):

    dist = {}

    tmp = collections.Counter(A)

    type_ = len(tmp)



    if type_ <= K:

        return 0



    for a, count in list(tmp.items()):

        if count not in list(dist.keys()):

            dist[count] = [a]

        else:

            dist[count].append(a)



    rewrite = 0

    i = 0

    for c in sorted(dist.keys()):

        for _ in dist[c]:

            i += 1

            rewrite += c

            if i == type_ - K:

                return rewrite





def main():

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

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

    ans = calc(A, K)

    print(ans)





if __name__ == "__main__":

    main()

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

cnt = [0 for _ in range(N)]



for i in map(int, input().split()):

    cnt[i-1] += 1



ans = 0

for i in sorted(cnt)[:N - K]:

    ans += i



print(ans)
import collections


def calc(A, K):
    dist = {}
    tmp = collections.Counter(A)
    type_ = len(tmp)
    if type_ <= K:
        return 0
    for a, count in list(tmp.items()):
        if count not in list(dist.keys()):
            dist[count] = [a]
        else:
            dist[count].append(a)
    rewrite = 0
    i = 0
    for c in sorted(dist.keys()):
        for _ in dist[c]:
            i += 1
            rewrite += c
            if i == type_ - K:
                return rewrite


def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    ans = calc(A, K)
    print(ans)


if __name__ == "__main__":
    main()

N, K = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in map(int, input().split()):
    cnt[i - 1] += 1
ans = 0
for i in sorted(cnt)[: N - K]:
    ans += i
print(ans)

-import collections - - -def calc(A, K): -    dist = {} -    tmp = collections.Counter(A) -    type_ = len(tmp) -    if type_ <= K: -        return 0 -    for a, count in list(tmp.items()): -        if count not in list(dist.keys()): -            dist[count] = [a] -        else: -            dist[count].append(a) -    rewrite = 0 -    i = 0 -    for c in sorted(dist.keys()): -        for _ in dist[c]: -            i += 1 -            rewrite += c -            if i == type_ - K: -                return rewrite - - -def main(): -    N, K = list(map(int, input().split())) -    A = list(map(int, input().split())) -    ans = calc(A, K) -    print(ans) - - -if __name__ == "__main__": -    main() +N, K = list(map(int, input().split())) +cnt = [0 for _ in range(N)] +for i in map(int, input().split()): +    cnt[i - 1] += 1 +ans = 0 +for i in sorted(cnt)[: N - K]: +    ans += i +print(ans)