"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var h = next(), w = next(), k = next();
  var s = nexts(h,1);
  var ans = 1e9;
  for(var i = 0; i < 1 << h-1; i++){
    var c = 0, j = i, x = 1, ary = [0];
    while(j){
      if(j & 1)c++, ary.push(x);
      j >>= 1;
      x++;
    }
    var map = xArray(0, ary.length);
    for(var x = 0; x < w && c < ans; x++){
      var id = ary.length-1;
      for(var y = h; y--;){
        if(y < ary[id])id--;
        if(s[y][x] === "1")map[id]++;
      }
      if(Math.max(...map) > k){
        c++;
        map = xArray(0,ary.length);
        id = ary.length-1;
        for(var y = h; y--;){
          if(y < ary[id])id--;
          if(s[y][x] === "1")map[id]++;
        }
      }
      if(Math.max(...map) > k)c = ans;
    }
    if(c < ans)ans = c;
  }
  return ans;
}