


fun main(args: Array<String>?) {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val dolls = IntArray(n){ readLine()!!.toInt()}
    val count = IntArray(m){0}
    val sumCount = Array(m){IntArray(n){0} }
    for (i in dolls.indices) {
        count[dolls[i] - 1]++
        sumCount[dolls[i] - 1][i]++
        if (i > 0) for (j in sumCount.indices) {
            sumCount[j][i] += sumCount[j][i - 1]
        }
    }
    val memo = IntArray(1 shl m){Int.MAX_VALUE}
    memo[0] = 0
    for (i in memo.indices) {
        val left = (0 until m).filter{i and (1 shl it) != 0}.sumBy(count::get)
        for (j in 0 until m) if (i and (1 shl j) == 0) {
            val right = left + count[j] - 1
            val sum = if (left > 0) sumCount[j][right] - sumCount[j][left - 1] else sumCount[j][right]
            memo[i or (1 shl j)] = java.lang.Math.min(memo[i or (1 shl j)], memo[i] + (count[j] - sum))
        }
    }
    println(memo.last())
}
