/*By Mohan Abhyas V*/
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}

p64 hashFn(v64 vc)
{
    ll p1 = 31, p2 = 97;
    ll m1 = 1e9+9, m2 = 998244353;
    ll hsv1 = 0, hsv2 = 0, p_pow1 = 1, p_pow2 = 1;
    forn(i, vc.size())
    {
        hsv1 = ((hsv1 + vc[i] + 1) * p_pow1) % m1;
        p_pow1 = (p_pow1 * p1) % m1;

        hsv2 = ((hsv2 + vc[i] + 1) * p_pow2) % m2;
        p_pow2 = (p_pow2 * p2) % m2;
    }
    return mp(hsv1, hsv2);
}
     
void solve(){
    ll h,w,k;
    cin>>h>>w>>k;
    vector<string> vc(h);
    forn(i, h)
    {
        cin>>vc[i];
    }
    if(h == 1)
    {
        ll ans = 0;
        ll curr = 0;
        ll cnt = 0;
        while(curr < w)
        {
            if(vc[0][curr] == '1') cnt++;
            if(cnt > k)
            {
                cnt -= k;
                ans++;
            }
            curr++;
        }
        return;
    }
    ll ans = INF;
    forn(hc, (1 << (h-1)))
    {

        ll tans = 0;
        v64 cuts;
        forn(i, (h-1))
        {
            if(hc & (1<<i)) cuts.pb(i);
        }
        vv64 els;
        ll prev = 0;
        for(auto it : cuts)
        {
            v64 tp;
            forsn(i, prev, it+1)
            {
                tp.pb(i);
            }
            els.pb(tp);
            prev = it+1;
        }
        v64 tp;
        forsn(i, prev, h)
        {
            tp.pb(i);
        }
        els.pb(tp);

        ll curr = 0;
        bool ini = 1;
        v64 pcs(h, 0);
        while(curr < w)
        {
            forn(i, h)
            {
                if(vc[i][curr] == '1') pcs[i]++;
            }
            bool fill = 0;
            forn(i, els.size())
            {
                ll sm = 0;
                for(auto it : els[i])
                {
                    sm += pcs[it];
                }
                if(sm > k)
                {
                    fill = 1;
                }
            }
            if(!fill)
            {
                ini = 0;
            }
            else if(fill && ini)
            {
                tans = INF;
                break;
            }
            else
            {
                curr--;
                tans++;
                ini = 1;
                pcs.resize(0);
                pcs.resize(h, 0);
            }
            curr++;
        }
        ans = min(ans, ll(tans+cuts.size()));
    }
    cout<<ans<<ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    //cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

/*
1) try dp
2) meet in the middle
3) correct complexity analysis
4) randomized algorithm
5) brute force

*/

Measured memory_bytes: 256