fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun pow(a: Int, p: Int): Long = pow(a.toLong(), p)
fun pow(a: Long, p: Int): Long = when {
    p == 0 -> 1L
    p % 2 == 1 -> a * pow(a, p - 1)
    else -> {
        val half = pow(a, p / 2)
        half * half
    }
}

fun solve(sc: java.util.Scanner) {
    val H = sc.nextInt()
    val W = sc.nextInt()
    val K = sc.nextInt()
    val A = Array(H) { sc.next().toCharArray() }

    val S = Array(H + 1) { Array(W + 1) { 0 } }
    for (h in 0 until H) {
        for (w in 0 until W) {
            var next = if (A[h][w] == '1') 1 else 0
            if (w > 0) {
                next += S[h + 1][w]
            }
            S[h + 1][w + 1] = next
        }
    }
    for (h in 1 until H) {
        for (w in 0 until W) {
            S[h + 1][w + 1] += S[h][w + 1]
        }
    }

//    S.forEach { println(it.joinToString()) }

    var result = Int.MAX_VALUE
    for (hs in 0 until pow(2, H).toInt()) {
        val hb = (1 until H).filter { b -> hs and (1 shl (b - 1)) != 0 } + H
        var nw = hb.count() - 1
        var wPrev = 0
        var w = 1
        while (w <= W) {
            var max = 0
            var hPrev = 0
            for (h in hb) {
                val n = S[h][w] - S[hPrev][w] - S[h][wPrev] + S[hPrev][wPrev]
                if (n > max) {
                    max = n
                }
                hPrev = h
            }
            if (max > K) {
                if (wPrev == w - 1) {
                    nw = -1
                    break
                }
                wPrev = w - 1
                nw++
                continue
            }
            w++
        }
        if (nw >= 0) {
            if (nw < result) {
                result = nw
            }
        }
    }
    println(result)
}
