#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint h,w,k;
      cin>>h>>w>>k;
      char t[h][w];
      rep(i,h){
          rep(j,w){
              cin>>t[i][j];
          }
      }
      lint x[h][w];
      rep(i,h){
          lint count=0;
          rep(j,w){
              if(t[i][j]=='1')count++;
              x[i][j]=count;
          }
      }
      lint ans=INF;
      rep(bit,1<<(h-1)){
          bool a[h];
          fill(a,a+h,false);
          a[h-1]=true;
          lint count=0;
          rep(i,(h-1)){
              if(bit&(1<<i)){
                  a[i]=true;
                  count++;
              }
          }
              lint now[h];
              fill(now,now+h,0);
              lint g=0;
              bool l=false;
               while(g<h){
                lint sum=x[g][0];
                while(!a[g]){
                    g++;
                    sum+=x[g][0];
                }
                if(sum>k){
                l=true;
                break;
                }
                g++;
                }
                if(l)continue;
                g=0;
              repp(i,1,w){
                  while(g<h){
                lint sum=x[g][i]-x[g][i-1];
                while(!a[g]){
                    g++;
                    sum+=x[g][i]-x[g][i-1];
                }
                if(sum>k){
                    //cout<<sum<<endl;
                l=true;
                break;
                }
                g++;
                }
                lint j=0;
                while(j<h){
                lint sum=x[j][i]-now[j];
                while(!a[j]){
                    j++;
                    sum+=x[j][i]-now[j];
                }
                if(sum>k){
                    count++;
                    rep(k,h)now[k]=x[k][i-1];
                    lint accum=0;
                    break;
                }
                j++;
                }
              }
        if(l)continue;
        ans=min(ans,count);
      }

    cout<<ans<<endl;
    
      }
      

Measured memory_bytes: 3728