import java.util.*

fun main(args: Array<String>) {
    val (H, W, K) = readIntList()
    val S = Array(H) { readString() }

    val cutH = BooleanArray(H - 1) { false }

    fun cut(cutH: BooleanArray): Int {
        val cutHcount = cutH.count { it }
        var pre = IntArray(cutHcount + 1) { 0 }
        var res = cutHcount
        repeat(W) { w ->
            var p = 0
            val tmp = IntArray(cutHcount + 1) { 0 }
            repeat(H) { h ->
                if (S[h][w] == '1') tmp[p]++
                if (h < H - 1 && cutH[h]) p++
            }
            if (tmp.any { it > K }) return 10000000

            if (pre.withIndex().any { tmp[it.index] + it.value > K }) {
                res++
                pre.fill(0)
            }
            pre = pre
                .withIndex()
                .map { it.value + tmp[it.index] }
                .toIntArray()
        }

        return res
    }

    fun f(b: Boolean, i: Int): Int {
        cutH[i] = b
        if (i == cutH.size - 1) return cut(cutH)
        return Math.min(
            f(true, i + 1),
            f(false, i + 1)
        )
    }

    println(Math.min(f(true, 0), f(false, 0)))
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)