#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    ll h,w,k;
    cin >> h >> w >> k;
    vector <vector <ll>> m(h,vector <ll>(w,0)),m2;
    m2=m;

    string s,s2;
    rep(i,h){
        cin >> s;
        rep(j,w){
            s2=s[j];
            if(s2=="1"){
                m[i][j]=1;
            }
        }
    }

    m2[0][0]=m[0][0];
    //cout << m[0][0] << " " << m[0][1] << endl;
    rep(i,h){
        rep(j,w){
             if(j==0){
                 m2[i][j]=m[i][j];
             }
             else{
                 m2[i][j]=m2[i][j-1]+m[i][j];
             }
        }
    }

    rep(j,w){
        rep(i,h){
            if(i!=0){
                m2[i][j]=m2[i][j]+m2[i-1][j];
            }
        }
    }

    /*rep(i,h){
        rep(j,w){
            cout << m2[i][j] << " ";
        }
        cout << endl;
    }*/

    //cout << m2[2][4] << endl;


    vector <int> v,v2,v3;
    ll ko=1001001001;
    int l,b;
    ll ans=0,ans2;
    rep(i,pow(2,h-1)){
        //cout << i << endl;
        v=v3;
        ans=0;
        ans2=0;
        b=0;
        rep(j,h-1){
            if(((i>>j)&1)==1){
                v.push_back(j);
            }
        }
        v.push_back(h-1);

        l=v.size();
        //cout << l << endl;
        ans=l-1;
        rep(j,w){
            rep(i2,l){
                if(i2==0 and b==0){
                    if(m2[v[0]][j]>k){
                        ++ans;
                        if((j-b)<=0){
                            ans2=-1;
                            break;
                        }
                        b=j;
                        break;
                    }
                }
                else if(i2==0){
                    if((m2[v[0]][j]-m2[v[0]][b-1])>k){
                        ++ans;
                        if((j-b)<=0){
                            ans2=-1;
                            break;
                        }
                        b=j;
                        break;
                    }
                    
                }
                else if(b==0){
                    if((m2[v[i2]][j]-m2[v[i2-1]][j])>k){
                        ++ans;
                        if((j-b)<=0){
                            ans2=-1;
                            break;
                        }
                        b=j;
                        break;
                    }
                    
                }
                else{
                    //cout << i << " " << j << " " <<  m2[v[i2]][j]-m2[v[i2]][b-1]-m2[v[i2-1]][j]+m2[v[i2-1]][b-1] << endl;
                    if((m2[v[i2]][j]-m2[v[i2]][b-1]-m2[v[i2-1]][j]+m2[v[i2-1]][b-1])>k){
                        ++ans;
                        if((j-b)<=0){
                            ans2=-1;
                            break;
                        }
                        b=j;
                    break;
                    }
                    
                }
                /*else{
                    if(m2[h-1][j]-m2[v[l-1]][b]){
                        ++ans;
                        if((j-b)<=1){
                            ans2=-1;
                            break;
                        }
                        b=j;
                        break;
                    }
                }*/
            }
            //cout << j << "  " << ans << endl;
        }

        //cout << i << " " << ans << endl;

        if(ans2==0){
            ko=min(ko,ans);
        }
    }

    cout << ko << endl;

    

    

    return 0;
}

Measured memory_bytes: 4244