import sys

from collections import Counter



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



def main():

    c = Counter(a)

    l = len(c)

    if l <= k:

        return 0



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

    res = 0

    for i in range(l - k):

        res += c[i][1]



    return res



if __name__ == '__main__':

    ans = main()

    print(ans)
import sys

from collections import Counter



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



def main():

    c = Counter(a)

    res = sum(sorted(c.values())[:-k])

    print(res)



if __name__ ==  '__main__':

    main()
import sys
from collections import Counter

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


def main():
    c = Counter(a)
    l = len(c)
    if l <= k:
        return 0
    c = sorted(list(c.items()), key=lambda x: x[1])
    res = 0
    for i in range(l - k):
        res += c[i][1]
    return res


if __name__ == "__main__":
    ans = main()
    print(ans)

import sys
from collections import Counter

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


def main():
    c = Counter(a)
    res = sum(sorted(c.values())[:-k])
    print(res)


if __name__ == "__main__":
    main()

-    l = len(c) -    if l <= k: -        return 0 -    c = sorted(list(c.items()), key=lambda x: x[1]) -    res = 0 -    for i in range(l - k): -        res += c[i][1] -    return res +    res = sum(sorted(c.values())[:-k]) +    print(res) -    ans = main() -    print(ans) +    main()