#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n,m,k;

    cin>>n>>m>>k;

    char a[n][m];

    li ans=(n-1)*(m-1);

    f(i,0,n-1)
    {       
        f(j,0,m-1)
        {
            cin>>a[i][j];
        }
    }

    if(n==1)
    {
        li har=0;

        li count=0;

        f(i,0,m-1)
        {
            if(a[0][i]=='1')
                count++;
            
            if(count>k)
            {
                count=1;
                har++;
            }
        }

        cout<<har;
        return 0;
    }

    li tp=(1<<(n-1))-1;

    vi v(n);

    f(i,0,n-1)
    {
        if(a[i][0]=='1')
            v[i]=1;
    }

    f(mask,0,tp)
    {
        li cnt=__builtin_popcount(mask);
        
        li tt,fg=1;

        f(i,0,m-1)
        { 
            if(a[0][i]=='1')
                tt=1;
            else
                tt=0;

            f(j,0,n-2)
            {
                if(mask&(1<<j))
                {
                    if(tt>k)
                        fg=0;

                    if(a[j+1][i]=='1')
                        tt=1;
                    else
                        tt=0;
                }
                else
                {
                    if(a[j+1][i]=='1')
                    tt++;
                }
            }
        }

        if(tt>k)
            fg=0;

        if(fg==0)
        {
            f(i,0,n-1)
            {
                if(a[i][0]=='1')
                    v[i]=1;
            }

            continue;
        }

        f(j,1,m-1)
        {
            // cout<<"j= "<<j<<endl;
            
            f(i,0,n-1)
            {
                if(a[i][j]=='1')
                    v[i]++;

                // cout<<v[i]<<" ";
            }

            // cout<<endl;

            li temp=v[0],flag=0;

            if(temp>k)
                flag=1;

            f(i,0,n-2)
            {
                if(mask&(1<<i))
                {
                    temp=v[i+1];
                }
                else
                {
                    temp+=v[i+1];
                }

                if(temp>k)
                    flag=1;
            }

            if(flag)
            {
                cnt++;
                // cout<<j<<endl;

                f(u,0,n-1)
                {
                    if(a[u][j]=='1')
                        v[u]=1;
                    else
                        v[u]=0;
                }

                // f(ttt,0,n-1)
                // {
                //     cout<<v[ttt]<<" ";
                // }
                // cout<<endl;
            }
        }

        f(i,0,n-1)
        {
            if(a[i][0]=='1')
                v[i]=1;
        }

        // cout<<cnt<<" "<<mask<<endl;

        ans=min(ans,cnt);
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 256