import java.lang.Math

fun main(args: Array<String>) {
    val (H, W, K) = readInputLine().split(" ").map { it.toInt() }

    val cake = Array(H) { readInputLine().toCharArray() }

    val sum = Array(H + 1) { IntArray(W + 1) }

    for (i in 0 until H) {
        for (j in 0 until W) {
            sum[i + 1][j + 1] += sum[i + 1][j]
            if (cake[i][j] == '1') {
                sum[i + 1][j + 1]++
            }
        }
    }

    for (i in 0 until H) {
        for (j in 0 until W) {
            sum[i + 1][j + 1] += sum[i][j + 1]
        }
    }

    var ans = H + W

    for (i in 0 until (1 shl H)) {
        val splitNum = mutableListOf<Int>()
        for (j in 1 until H) {
            if ((i shr (j - 1)) % 2 == 1) {
                splitNum.add(j)
            }
        }
        splitNum.add(H)
        var splitCnt = splitNum.size - 1

        var befSplitW = 0
        var unSplittable = false
        for (j in 1..W) {
            var befSplitV = 0
            var split = false
            for (sp in splitNum) {
                val areaCnt = sum[sp][j] - sum[befSplitV][j] - sum[sp][befSplitW] + sum[befSplitV][befSplitW]
                if (areaCnt > K) {
                    split = true
                }
                befSplitV = sp
            }
            if (split) {
                if (j - 1 == befSplitW) {
                    unSplittable = true
                    break
                }
                befSplitW = j - 1
                splitCnt++
            }
        }

        if (unSplittable) {
            continue
        }

        ans = Math.min(ans, splitCnt)
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
