#!/usr/bin/env python3

import sys

import collections



def solve(N: int, K: int, A: "List[int]"):

    a_counter = collections.Counter(A)

    if len(a_counter) <= K:

        print((0))

        return 



    values = sorted(list(a_counter.values()))

    answer = 0

    for i in range(len(a_counter)-K):

        answer += values[i]

    print(answer)

    return





# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    K = int(next(tokens))  # type: int

    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    solve(N, K, A)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3

import sys

from collections import Counter



def solve(N: int, K: int, A: "List[int]"):

    counter = list(Counter(A).values())

    counter.sort()



    if len(counter) <= K:

        print((0))

    else:

        need = len(counter)-K

        print((sum(counter[:need])))



    return





# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

def main():

    def iterate_tokens():

        for line in sys.stdin:

            for word in line.split():

                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int

    K = int(next(tokens))  # type: int

    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"

    solve(N, K, A)



if __name__ == '__main__':

    main()

#!/usr/bin/env python3
import sys
import collections


def solve(N: int, K: int, A: "List[int]"):
    a_counter = collections.Counter(A)
    if len(a_counter) <= K:
        print((0))
        return
    values = sorted(list(a_counter.values()))
    answer = 0
    for i in range(len(a_counter) - K):
        answer += values[i]
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, K: int, A: "List[int]"):
    counter = list(Counter(A).values())
    counter.sort()
    if len(counter) <= K:
        print((0))
    else:
        need = len(counter) - K
        print((sum(counter[:need])))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == "__main__":
    main()

-import collections +from collections import Counter -    a_counter = collections.Counter(A) -    if len(a_counter) <= K: +    counter = list(Counter(A).values()) +    counter.sort() +    if len(counter) <= K: -        return -    values = sorted(list(a_counter.values())) -    answer = 0 -    for i in range(len(a_counter) - K): -        answer += values[i] -    print(answer) +    else: +        need = len(counter) - K +        print((sum(counter[:need])))