program problem_committee
  implicit none
  integer :: n, k, c(26) = 0, i, m, x
  character(1) :: s
  read(*,*) n, k
  do i = 1, n
    read(*,*) s
    m = ichar(s)-64
    c(m) = c(m)+1
  end do
  m = 0
  do
    call bitonic_sort(c,.false.)
    x = c(k)
    if (x == 0) exit
    m = m+x
    c(1:k) = c(1:k)-x
  end do
  write(*,'(i0)') m
contains
  recursive subroutine bitonic_sort(a,ascend)
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n
    n = size(a)
    if (n == 1) return
    call bitonic_sort(a(1:n/2),.not.ascend)
    call bitonic_sort(a(n/2+1:n),ascend)
    call bitonic_merge(a,ascend)
  end
  recursive subroutine bitonic_merge(a,ascend)
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n, m, i, b
    n = size(a)
    if (n == 1) return
    m = 1
    do while (2*m < n)
      m = 2*m
    end do
    do i = 1, n-m
      if ((a(i) > a(i+m)) .eqv. ascend) then
        b = a(i)
        a(i) = a(i+m)
        a(i+m) = b
      end if
    end do
    call bitonic_merge(a(1:m),ascend)
    call bitonic_merge(a(m+1:n),ascend)
  end
end program problem_committee