//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};


string s[11];
ll cums[11][1005];
vector<ll>v;


bool ispossible(ll st,ll en,ll c,ll k){
    ll sz=v.size();
    for(ll i=1;i<sz;i++){
        ll cnt=0;
        for(ll j=st;j<=en;j++){
            cnt += cums[v[i]][j]-cums[v[i-1]][j];
        }
        if(cnt>k) return 0;
    }
    return 1;
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);   
    ll r,c,k,ans=0;
    sfl(r),sfl(c),sfl(k);
    for(ll i=1;i<=r;i++){
        cin >> s[i];
        s[i]="0"+s[i];
    }
    for(ll i=1;i<=c;i++){
        for(ll j=1;j<=r;j++){
            cums[j][i] = cums[j-1][i]+(s[j][i]-'0');
        }
        ans += cums[r][i];
    }

    ll mn,prev,tmp,N=1ll<<(r-1),S=0,cnt,now,sz;
    for(ll mask = 0;mask<N;mask++){
        mn = prev= tmp=cnt=0;
        v.clear();
        bool f=1;
        v.pb(0);
        for(ll i=1;i<r;i++){
            if(CHECK(mask,i-1)){
                mn++;
                v.pb(i);
            }
        }
        v.pb(r);
        sz = v.size();
        for(ll i=1;i<=c;i++){
            for(ll j=1;j<sz;j++){
                if(cums[v[j]][i]-cums[v[j-1]][i]>k) f=0;
            }
        }
        if(!f) continue;
        cnt=0;
        ll lw=1,hi=c,mid,ind=1;
        prev = 0;
        while(1){
            lw = prev+1;
            hi = c;
            while(lw<=hi){
                mid = (lw+hi)/2;
                if(ispossible(prev+1,mid,c,k)){
                    ind = mid;
                    lw = mid+1;
                }
                else{
                    hi = mid-1;
                }
            }
            cnt++;
            prev = ind;
            if(prev>=c) break;
        }

        ans = min(ans,mn+cnt);
    }
    ans = max(0ll,ans-1);
    pfl(ans);
    return 0;
}


Measured memory_bytes: 3852