#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL h;
    LL w;
    LL k;
    cin >> h >> w >> k;
    vector<vector<LL>> d(h, vector<LL>(w, 0));
    string s;
    for(LL i=0; i<h; i++){
        cin >> s;
        LL tmp;
        tmp=s[0]-'0';
        d[i][0]=tmp;
        for(LL j=1; j<w; j++){
            tmp=s[j]-'0';
            d[i][j]=d[i][j-1]+tmp;
        }
    }

    vector<LL> b(h);
    b[0]=0;
    LL min_ans=h*w;
    for(LL i=0; i<(1<<(h-1)); i++){
        LL tmp=i;
        LL ans_h=0;
        LL ans_w=0;
        b[0]=0;
        vector<LL> prev(h, 0);
        for(LL j=1; j<h; j++){
            if(tmp%2==1){
                b[j]=b[j-1]+1;
                ans_h++;
            }else{
                b[j]=b[j-1];
            }
            tmp/=2;
        }
        LL tmp_sum_now;
        LL tmp_sum_acc;
        bool is_cut;
        bool is_ok=true;
        ans_w=0;
        for(LL j=0; j<w; j++){
            is_cut=false;
            if(j==0){
                tmp_sum_now=d[0][j];
                tmp_sum_acc=0;
            }else{
                tmp_sum_now=d[0][j]-d[0][j-1];
                tmp_sum_acc=d[0][j-1]-prev[0];
            }
            for(LL l=1; l<h; l++){
                if(b[l]==b[l-1]){
                    if(j==0){
                        tmp_sum_now+=d[l][j];
                        tmp_sum_acc+=0;
                    }else{
                        tmp_sum_now+=d[l][j]-d[l][j-1];
                        tmp_sum_acc+=d[l][j-1]-prev[l];
                    }
                }else{
                    if(tmp_sum_now>k){
                        is_ok=false;
                    }
                    if(tmp_sum_now+tmp_sum_acc>k){
                        is_cut=true;
                    }
                    if(j==0){
                        tmp_sum_now=d[l][j];
                        tmp_sum_acc=0;
                    }else{
                        tmp_sum_now=d[l][j]-d[l][j-1];
                        tmp_sum_acc=d[l][j-1]-prev[l];
                    }
                }
                //cout << j << " " << tmp_sum_now << " " << tmp_sum_acc << " " << k << endl;
                if(l==h-1){
                    if(tmp_sum_now>k){
                        is_ok=false;
                    }
                    if(tmp_sum_now+tmp_sum_acc>k){
                        is_cut=true;
                    }
                }
                //cout << i << " " << j << " " << b[l] << " " << tmp_sum_now << " " << tmp_sum_acc << endl;
            }
            if(is_ok==false){
                break;
            }else if(is_cut==true){
                //cout << j << endl;
                ans_w++;
                for(LL l=0; l<h; l++){
                    prev[l]=d[l][j-1];
                }
            }
        }
        //cout << i << " " << ans_h << " " << ans_w << " " << is_ok << endl;
        if(is_ok==true){
            min_ans=min(min_ans, ans_h+ans_w);
        }
    }

    cout << min_ans << endl;

    return 0;
}


Measured memory_bytes: 3580