read a
b=(`echo $a`)
read c
d=(`echo $c`)
e=`echo ${d[@]} | sed 's/\s/\n/g' | sort -u | wc -l`
f=(`echo ${d[@]} | sed 's/\s/\n/g' | sort | uniq -c | sort -n`)
z=0

if [ $e -ge ${b[1]} ];then
    g=$(($e - ${b[1]}))
    for ((i=0;i < ${#f[*]};i+=2));do
        if [ $g -gt 0 ];then
            z=$((z + ${f[i]}))
            g=$((--g))
        fi
    done
fi
echo $z