import java.util.*

fun main(args: Array<String>) = abc159e()

fun abc159e() {
    val (h, w, k) = readLine()!!.split(' ').map { it.toInt() }
    // true: white chocolate
    val grid = Array(h) { readLine()!!.toCharArray().map { Character.getNumericValue(it) }.toIntArray() }

    var answer = Int.MAX_VALUE

    bitWholeSearch@ for (bit in 0 until Math.pow(2.0, h.toDouble()).toLong()) {
        val bitSet = BitSet.valueOf(longArrayOf(bit))
        if (bitSet[0]) continue

        var above = 0
        var divCount = 0

        val rows = mutableListOf<List<IntArray>>()

        while (above < h) {
            var below = above
            while (below + 1 < h && !bitSet[below + 1]) below++
            rows.add(grid.slice(above..below))
            above = below + 1
        }

        val whiteOnLeft = IntArray(rows.size)

        for (x in 0 until w) {
            val whiteOnRows = rows.map { row -> row.map { it[x] }.sum() }
            if (whiteOnRows.any { it > k }) continue@bitWholeSearch
            if (whiteOnRows.mapIndexed { index, white -> white + whiteOnLeft[index] }.any { it > k }) {
                divCount++
                for (i in whiteOnLeft.indices) whiteOnLeft[i] = whiteOnRows[i]
            } else {
                for (i in whiteOnLeft.indices) whiteOnLeft[i] += whiteOnRows[i]
            }
        }

        answer = Math.min(answer, bitSet.cardinality() + divCount)
    }

    println(answer)
}
