#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    ll h, w, f;
    vector< string > s;
    cin>>h>>w>>f;
    ll i;
    FOR0(i, h)
    {
        string temp;
        cin>>temp;
        s.pb(temp);
    }
    int j;
    int lim = pow(2, h-1);
    int ans = inf;
    FOR0(j, lim)
    {
        int cuts[11] = {};
        int nc = 0;
        FOR0(i, h-1) if((1<<i)&j) nc++;
        int ncuts[11] = {};
        int k;
        int cans = nc;
        FOR0(i, w)
        {
            int cur = 0;
            int num = 0;
            FOR0(k, h)
            {
                if(s[k][i] == '1') cur++;
                if((1<<k)&j) 
                {
                    ncuts[num] = cur;
                    cur = 0 ;
                    num++;
                }
            }
            ncuts[num] = cur;
            bool is = true;
            FOR0(k, nc+1)
            {
                if(cuts[k]+ncuts[k] > f)
                {
                    is = false;
                    break;
                }
            }
            if(!is)
            {
                FOR0(k, nc+1)
                    if(cuts[k] > f) break;
                if(k == nc+1) 
                {
                    cans++;
                    FOR0(k, nc+1)
                    {
                        cuts[k] = ncuts[k];
                        ncuts[k] = 0;
                    }
                }
                else break;
            }
            else 
            {
                FOR0(k, nc+1)
                {
                    cuts[k] += ncuts[k];
                    ncuts[k] = 0;
                }
            }
        }
        if(i == w)
        {
            FOR0(k, nc+1)
                if(cuts[k] > f) break;
            if(k == nc+1)
            {
                ans = MIN2(ans, cans);
            }
        }
    }
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 384