# _*_ coding:utf-8 _*_

#  Atcoder_Beginnger_Contest081-C

#  TODO https://atcoder.jp/contests/abc081/tasks/arc086_a

import collections as col



def solveProblem(neededBallKind,BallsList):

	AsListCounter = col.Counter(BallsList)

	allBallKind = len(AsListCounter)

	sortCounter = sorted(list(AsListCounter.items()),reverse=False,key=lambda x:x[1])

	replaceBallCount = 0

	replaceBallKind = allBallKind-neededBallKind

	if replaceBallKind <= 0:

		answer = 0

	else:

		for k,v in sortCounter:

			replaceBallCount = replaceBallCount + v

			replaceBallKind = replaceBallKind - 1

			if replaceBallKind <= 0:

				break

		answer = replaceBallCount

	return answer



if __name__ == '__main__':

	_,K = list(map(int,input().strip().split(' ')))

	AsList = list(map(int,input().strip().split(' ')))

	solution = solveProblem(K,AsList)

	print(("{}".format(solution)))

# Problem: atcoder.jp/contests/abc081/tasks/arc086_a

# Python 1st Try



import sys

# from collections import defaultdict

import collections as col

# import pprint

# import heapq,copy

# from collections import deque

def II(): return int(sys.stdin.readline())

def MI(): return list(map(int, sys.stdin.readline().split()))

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]





def solver(ALLNUM, KIND, ball_numbers):

    result = 0

    # prp = pprint.pprint

    counter_result = col.Counter(ball_numbers)

    ball_num_len = len(counter_result)

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

    # prp(counter_result_sorted)

    if ball_num_len <= KIND:

        return 0

    reduce_kind = ball_num_len - KIND

    # prp(reduce_kind)

    for _, ballCount in counter_result_sorted:

        result += ballCount

        reduce_kind = reduce_kind - 1

        # prp(reduce_kind)

        if reduce_kind <= 0:

            break

    return result





if __name__ == "__main__":

    N, K = MI()

    Ai = list(map(int, sys.stdin.readline().split()))

    # print(Ai)

    print(("{}".format(solver(N, K, Ai))))

# _*_ coding:utf-8 _*_
#  Atcoder_Beginnger_Contest081-C
#  TODO https://atcoder.jp/contests/abc081/tasks/arc086_a
import collections as col


def solveProblem(neededBallKind, BallsList):
    AsListCounter = col.Counter(BallsList)
    allBallKind = len(AsListCounter)
    sortCounter = sorted(list(AsListCounter.items()), reverse=False, key=lambda x: x[1])
    replaceBallCount = 0
    replaceBallKind = allBallKind - neededBallKind
    if replaceBallKind <= 0:
        answer = 0
    else:
        for k, v in sortCounter:
            replaceBallCount = replaceBallCount + v
            replaceBallKind = replaceBallKind - 1
            if replaceBallKind <= 0:
                break
        answer = replaceBallCount
    return answer


if __name__ == "__main__":
    _, K = list(map(int, input().strip().split(" ")))
    AsList = list(map(int, input().strip().split(" ")))
    solution = solveProblem(K, AsList)
    print(("{}".format(solution)))

# Problem: atcoder.jp/contests/abc081/tasks/arc086_a
# Python 1st Try
import sys

# from collections import defaultdict
import collections as col

# import pprint
# import heapq,copy
# from collections import deque
def II():
    return int(sys.stdin.readline())


def MI():
    return list(map(int, sys.stdin.readline().split()))


def LI():
    return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number):
    return [LI() for _ in range(rows_number)]


def solver(ALLNUM, KIND, ball_numbers):
    result = 0
    # prp = pprint.pprint
    counter_result = col.Counter(ball_numbers)
    ball_num_len = len(counter_result)
    counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1])
    # prp(counter_result_sorted)
    if ball_num_len <= KIND:
        return 0
    reduce_kind = ball_num_len - KIND
    # prp(reduce_kind)
    for _, ballCount in counter_result_sorted:
        result += ballCount
        reduce_kind = reduce_kind - 1
        # prp(reduce_kind)
        if reduce_kind <= 0:
            break
    return result


if __name__ == "__main__":
    N, K = MI()
    Ai = list(map(int, sys.stdin.readline().split()))
    # print(Ai)
    print(("{}".format(solver(N, K, Ai))))

-# _*_ coding:utf-8 _*_ -#  Atcoder_Beginnger_Contest081-C -#  TODO https://atcoder.jp/contests/abc081/tasks/arc086_a +# Problem: atcoder.jp/contests/abc081/tasks/arc086_a +# Python 1st Try +import sys + +# from collections import defaultdict +# import pprint +# import heapq,copy +# from collections import deque +def II(): +    return int(sys.stdin.readline()) -def solveProblem(neededBallKind, BallsList): -    AsListCounter = col.Counter(BallsList) -    allBallKind = len(AsListCounter) -    sortCounter = sorted(list(AsListCounter.items()), reverse=False, key=lambda x: x[1]) -    replaceBallCount = 0 -    replaceBallKind = allBallKind - neededBallKind -    if replaceBallKind <= 0: -        answer = 0 -    else: -        for k, v in sortCounter: -            replaceBallCount = replaceBallCount + v -            replaceBallKind = replaceBallKind - 1 -            if replaceBallKind <= 0: -                break -        answer = replaceBallCount -    return answer + +def MI(): +    return list(map(int, sys.stdin.readline().split())) + + +def LI(): +    return list(map(int, sys.stdin.readline().split())) + + +def LLI(rows_number): +    return [LI() for _ in range(rows_number)] + + +def solver(ALLNUM, KIND, ball_numbers): +    result = 0 +    # prp = pprint.pprint +    counter_result = col.Counter(ball_numbers) +    ball_num_len = len(counter_result) +    counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1]) +    # prp(counter_result_sorted) +    if ball_num_len <= KIND: +        return 0 +    reduce_kind = ball_num_len - KIND +    # prp(reduce_kind) +    for _, ballCount in counter_result_sorted: +        result += ballCount +        reduce_kind = reduce_kind - 1 +        # prp(reduce_kind) +        if reduce_kind <= 0: +            break +    return result -    _, K = list(map(int, input().strip().split(" "))) -    AsList = list(map(int, input().strip().split(" "))) -    solution = solveProblem(K, AsList) -    print(("{}".format(solution))) +    N, K = MI() +    Ai = list(map(int, sys.stdin.readline().split())) +    # print(Ai) +    print(("{}".format(solver(N, K, Ai))))