import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val h = scn.nextInt()
	val w = scn.nextInt()
	val k = scn.nextInt()
	val choco = Array(h){scn.next().map{ it.toString().toInt() }}
	val sm = Array(h){IntArray(w)}
	for (r in sm.indices){
		for (c in sm[0].indices){
			val bef = if (r!=0) sm[r-1][c] else 0
			sm[r][c] = bef + choco[r][c]
		}
	}
	var ans = h+w
	dhloop@ for (dhb in 0 until 1.shl(h-1)) {
		val s = (0 until h).filter { it==h-1 || 1.shl(it).and(dhb) != 0 }
		val t = IntArray(s.size)
		var div = s.size-1
		for (c in 0 until w){
			var f = false
			for (dhi in s.indices){
				t[dhi] += sm[s[dhi]][c] - (if (dhi!=0) sm[s[dhi-1]][c] else 0 )
				if (t[dhi]>k){
					f = true
					break
				}
			}
			if (f) {
				div++
				for (dhi in s.indices){
					t[dhi] = sm[s[dhi]][c] - (if (dhi!=0) sm[s[dhi-1]][c] else 0 )
					if (t[dhi]>k) continue@dhloop
				}
			}
		}
		ans = Math.min(ans, div)
	}
	print(ans)
}