import collections

def solve(n, k, a_list):



    counter = collections.Counter()



    for i in a_list:

        counter[i] += 1



    key_num = len(list(counter.keys()))

    if key_num > k:

        tmp = sorted(list(counter.items()), key=lambda x: x[1])

        ans = sum([v for k, v in tmp[: key_num - k]])

    else:

        ans = 0



    return ans



if __name__ == "__main__":

    n, k = [int(i) for i in input().split()]

    a_list = [int(i) for i in input().split()]

    print((solve(n, k, a_list)))

import collections

def solve(n, k, a_list):



    counter = collections.Counter()



    for i in a_list:

        counter[i] += 1



    tmp = sorted(list(counter.values()), reverse=True)

    ans = n - sum(tmp[:k])

    

    return ans



if __name__ == "__main__":

    n, k = [int(i) for i in input().split()]

    a_list = [int(i) for i in input().split()]

    print((solve(n, k, a_list)))
import collections


def solve(n, k, a_list):
    counter = collections.Counter()
    for i in a_list:
        counter[i] += 1
    key_num = len(list(counter.keys()))
    if key_num > k:
        tmp = sorted(list(counter.items()), key=lambda x: x[1])
        ans = sum([v for k, v in tmp[: key_num - k]])
    else:
        ans = 0
    return ans


if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print((solve(n, k, a_list)))

import collections


def solve(n, k, a_list):
    counter = collections.Counter()
    for i in a_list:
        counter[i] += 1
    tmp = sorted(list(counter.values()), reverse=True)
    ans = n - sum(tmp[:k])
    return ans


if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print((solve(n, k, a_list)))

-    key_num = len(list(counter.keys())) -    if key_num > k: -        tmp = sorted(list(counter.items()), key=lambda x: x[1]) -        ans = sum([v for k, v in tmp[: key_num - k]]) -    else: -        ans = 0 +    tmp = sorted(list(counter.values()), reverse=True) +    ans = n - sum(tmp[:k])