fun main(arg: Array<String>) {
    val (H, W, K) = listOfInt()
    val S = Array(H) { next().map { it - '0' }.toIntArray() }
    val INF = 1001001001
    var ans = INF
    for (b in 0 until (1 shl (H - 1))) {
        var G = 0
        val gr = IntArray(H)
        for (h in 0 until H) {
            gr[h] = G
            if (((b shr h) and 1) == 1) G += 1
        }
        G += 1
        val c = Array(G) { IntArray(W) }
        for (h in 0 until H) for (w in 0 until W) c[gr[h]][w] += S[h][w]
        var num = G - 1
        val now = IntArray(G)
        fun add(w: Int): Boolean {
            for (g in 0 until G) now[g] += c[g][w]
            for (g in 0 until G) if (now[g] > K) return false
            return true
        }
        for (w in 0 until W) {
            if (!add(w)) {
                num += 1
                for (g in 0 until G) now[g] = 0
                if (!add(w)) {
                    num = INF
                    break
                }
            }
        }
        ans = Math.min(ans, num)
    }
    println(ans)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
