#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define vi vector<long long>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
ll mod=1000000007;
ll large=1e18;
ll neg=-1e18;
ll N=500000;
ll mod1=998244353;
struct pii
{
   ll x;
   ll y;
};
struct edge
{
   ll from;
   ll to;
   ll w;
   ll id;
};
ll find(ll a,ll p[])
{
   //cout<<"find "<<a<<endl;
   if(a==p[a])
   return a;
   else return p[a]=find(p[a],p);

}
void join(ll a,ll b,ll p[],ll sz[])
{
   a=find(a,p);
   b=find(b,p);
   if(a!=b)
   {
      if(sz[a]<sz[b])
      swap(a,b);
      sz[a]+=sz[b];
      p[b]=a;
   }
}
ll power(ll a,ll b,ll mod)
{
   ll res=1;
   while(b>0)
   {
      if(b&1)
      res=(res*a)%mod;
      b=b/2;
      a=(a*a)%mod;
   }
   return res;
}
ll inverse(ll x, ll p)
{
   return power(x,p-2,p);
}
ll hash1(ll x,ll y)
{
   return x+y+x*y;
}
/*ll f[200000]={0};

void ini()
{
   f[0]=1;
   for(ll i=1;i<=200000;i++)
   f[i]=(i*f[i-1])%mod;
}*/
void build(ll tree[],ll v,ll l,ll r,ll dp[])
{
   if(l==r)
      tree[v]=dp[l];
   else
   {
      ll m=(l+r)/2;
      build(tree,2*v,l,m,dp);
      build(tree,2*v+1,m+1,r,dp);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}
ll query(ll tree[],ll v,ll l,ll r,ll tl,ll tr)
{
   if(l==tl && tr==r)
   {
    //  cout<<"max of "<<tl<<" "<<tr<<" "<<tree[v]<<endl;
      return tree[v];
   }
   else
   {
      ll m=(l+r)/2;
      if(tr<=m)
      {
         ll z1= query(tree,2*v,l,m,tl,tr);
     //    cout<<"max of "<<tl<<" "<<tr<<" "<<z1<<endl;
         return z1;
      }
      else if(tl>m)
      {
         ll z2= query(tree,2*v+1,m+1,r,tl,tr);
      //   cout<<"max of "<<tl<<" "<<tr<<" "<<z2<<endl;
         return z2;
      }
      else 
      {
         ll z=query(tree,2*v,l,m,tl,m);
         ll z1=query(tree,2*v+1,m+1,r,m+1,tr);
       //  cout<<"max of "<<tl<<" "<<tr<<" "<<max(z1,z)<<endl;
         return max(z1,z);
      }
      
      
   }
}
void update(ll tree[],ll v,ll l,ll r,ll pos,ll element)
{
   if(l==r && l==pos)
   tree[v]=element;
   else
   {
      ll m=(l+r)/2;
      if(pos<=m)
      update(tree,2*v,l,m,pos,element);
      else
      update(tree,2*v+1,m+1,r,pos,element);
      tree[v]=max(tree[2*v],tree[2*v+1]);
   }
}

/*ll ncr(ll n,ll r)
{
   ll res=1;
   ll k=f[n];
   ll v=inverse(f[n-r],mod);
   ll u=inverse(f[r],mod);
   ll x=(u*v)%mod;
   k=(k*x)%mod;
   return k;
}*/
ll max_n=1e6+100;
ll hash2(ll x,ll y,ll W)
{
   return (x-1)*W+y;
}
pii rev(ll u,ll W)
{
   pii ans;
   if(u%W==0)
   {
      ans.y=W;
      ans.x=(u-W)/W+1;
   }
   return ans;

}
ll MAX_N=200000;
string tobin(ll a,ll sz)
{
   string s;
   ll r=0;
   while(a>0)
   {
      if(a%2==0)
      s.pb('0');
      else
      s.pb('1');
      a/=2;
      r++;
   }
   while(r<sz)
   {
      s.pb('0');
      r++;
   }
   reverse(s.begin(),s.end());
   return s;
}
ll tolong(string s)
{
   ll sz=s.size();
   ll ans=0;
   for(ll i=0;i<sz;i++)
   {
      if(s.at(i)=='1')
      ans+=(ll)pow(2,sz-i-1);
      
   }
   return ans;
}
void printvec(vector<ll> &c)
{
   for(ll i : c)
   cout<<i<<" ";
   cout<<endl;
}
void printarr(ll a[],ll n)
{
   for(ll i=0;i<n;i++)
   cout<<a[i]<<" ";
   cout<<endl;
}

int main()
{
  
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll h,w,k;
   cin>>h>>w>>k;
    char input[h][w];
   for(ll i=0;i<h;i++)
   {
      for(ll j=0;j<w;j++)
      cin>>input[i][j];
   }
   ll col[h][w];
   for(ll i=0;i<w;i++)
   {
      if(input[0][i]=='1')
      col[0][i]=1;
      else
      col[0][i]=0;
   }
   for(ll i=1;i<h;i++)
   {
      for(ll j=0;j<w;j++)
      {
         if(input[i][j]=='1')
         col[i][j]=1+col[i-1][j];
         else
         col[i][j]=col[i-1][j];
      }
   }
   ll sz=(ll)pow(2,h-1);
   ll ans=1e18;
   for(ll i=0;i<sz;i++)
   {
     string s=tobin(i,h-1);
     ll size=__builtin_popcountll(i);
     size++;
     ll d[size][w]={{0}};
     for(ll g=0;g<size;g++)
     {
        for(ll j=0;j<w;j++)
        d[g][j]=0;
     }
     ll cur=0;
     for(ll it=0;it<w;it++)
     {
        cur=0;
        ll label[h]={0};
        label[0]=cur;
        ll j=0;
        ll f=1;
        while(j<h-1)
        {
           if(s.at(j)=='1')
           {
              cur++;
           }
           label[f]=cur;
           j++;
           f++;
        }
        for(f;f<h;f++)
        label[f]=cur;
        for(ll j=0;j<h;j++)
        d[label[j]][it]=d[label[j]][it]+input[j][it]-'0';
     }
     ll ttt=1;
 ///  cout<<i<<" "<<s<<endl;
   /*for(ll f=0;f<size;f++)
   {
      for(ll j=0;j<w;j++)
      cout<<d[f][j]<<" ";
      cout<<endl;
   }*/
     for(ll i1=0;i1<w;i1++)
     {
        for(ll j=0;j<size;j++)
        {
           if(d[j][i1]>k)
           {
              ttt=0;
              break;
           }
        }
        if(ttt==0)
        break;
     }
     ll res=size-1;

     ll a[size]={0};
     ll start=0;
   ll u=0;
   while(u<w && ttt)
   {
      if(start==u)
      {
         for(ll i1=0;i1<size;i1++)
         a[i1]=d[i1][u];
      }
      else
      {
         for(ll i1=0;i1<size;i1++)
         a[i1]+=d[i1][u];
      }
      ll tt=1;
      for(ll f=0;f<size;f++)
      {
         if(a[f]>k)
         {
            tt=0;
            break;
         }
      }
      if(tt==0)
      {
         for(ll ii=0;ii<size;ii++)
         a[ii]=0;
         res++;
         start=u;
      }
      else
      u++;
      
   }
   //cout<<"ans for "<<i<<" "<<s<<" is "<<res<<endl;
   //cout<<ttt<<endl;
   if(ttt)
   ans=min(res,ans);
     


   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 4096