#include <bits/stdc++.h>

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<int>v,v2;
int a[20][1009];
int cnt[11];
int h,w,k;
int solve(int mask)
{
    vector<int>v,v2;
    MEM(cnt,0);
    for(int i=0; i<h-1; i++)
    {

        if((1<<i)&mask)
            v.pb(i+1);
    }
    v.pb(h);
    int y=0;
    int c=0;
    for(int i=1; i<=w; i++)
    {
        y=0;
        int f=0;
        for(int j=0; j<v.size(); j++)
        {
            if(a[v[j]][i]-a[y][i]>k)
                return w+h;
            cnt[v[j]]+=a[v[j]][i]-a[y][i];
            if(cnt[v[j]]+a[v[j]][i+1]-a[y][i+1]>k)
            {
                f=1;
                v2.pb(i);
                break;
            }
            y=v[j];
        }
//        for(int j=1; j<=w; j++)
//        {
//            cout<<cnt[j]<<" ";
//        }
//        cout<<endl;
        if(f)
        {
            y=0;
            for(int j=1; j<=w; j++)
            {
//                cout<<cnt[j]<<" ";
                cnt[j]=0;

            }

        }

    }
//    cout<<"result ...\n";
//    for(int i=0; i<v.size(); i++)
//        cout<<v[i]<<" ";
//    cout<<endl;
//
//    for(int i=0; i<v2.size(); i++)
//        cout<<v2[i]<<" ";
//    cout<<endl<<"end "<<mask<<endl;

    return int(v.size()-1)+(int)v2.size();
}
int main()
{
    FastRead;
    cin>>h>>w>>k;
    char ch[h+1][w+1];
    for(int i=1; i<=h; i++)
    {

        for(int j=1; j<=w; j++)
        {
            cin>>ch[i][j];
            if(ch[i][j]=='1')
                a[i][j]++;
            a[i][j]+=a[i-1][j];
        }
    }
    //    for(int i=1; i<=h; i++)
//    {
//        for(int j=1; j<=w; j++)
//            cout<<a[i][j]<<" ";
//        cout<<endl;
//    }
//    cout<<endl;
    int mn=w+h;
    for(int i=0; i<(1<<h); i++)
    {
        mn=min(mn,solve(i));
    }
    cout<<mn;



}


Measured memory_bytes: 384