#include<bits/stdc++.h>
using namespace std;
int main() {
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  for(auto&& e:s) {
    cin>>e;
  }
  int res=1e9;
  for(int bt=0;bt<1<<(h-1);++bt) {
    vector<int> p{0};
    for(int i=1;i<h;++i) {
      if(bt>>(i-1)&1) {
        p.push_back(i);
      }
    }
    p.push_back(h);
    int n=p.size()-1;
    int cur=n-1;
    int l=0,r=0;
    while(l<w) {
      vector<int> c(n);
      while(r<w) {
        for(int t=0;t<n;++t) {
          for(int i=p[t];i<p[t+1];++i) {
            c[t] += s[i][r] == '1';
          }
        }
        if(*max_element(begin(c),end(c))>k){
          break;
        }
        ++r;
      }
      if (l == r) {
        cur = 1e9;
        break;
      }
      l=r;
      if(l<w) cur++;
    }
    res=min(res,cur);
  }
  cout<<res;
}