#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int H,W,K,ans=1000000000;
int cnt[10][1005];
int main(void){
    cin>>H>>W>>K;
    string S[H];
    rep(i,H)cin>>S[i];

    rep(div,1<<(H-1)){
        int g=0;
        vector<int>id(H);
        rep(i,H){
            id[i]=g;
            if(div>>i&1)++g;
        }
        ++g;
        rep(i,g)rep(j,W)cnt[i][j]=0;
        rep(i,H)rep(j,W)cnt[id[i]][j]+=(S[i][j]-'0');

        int num=g-1;
        vector<int>now(g);
        auto add=[&](int j){
            rep(i,g)now[i]+=cnt[i][j];
            rep(i,g)if(now[i]>K)return false;
            return true;            
        };
        rep(j,W){
            if(!add(j)){
                num++;
                now=vector<int>(g);
                if(!add(j)){
                    num=1001001001;
                    break;
                }
            }
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}