#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll int128_t
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}
 
int inverse(int x){
    return power(x,mod-2,mod);
}

int const N = 2e5+555;
int const inf = 2e16;
int a[12][1005];
int c[12][1005];

void solve(){  
    int n,i,j,l,m,k;
    cin >> n >> m >> k;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            char c; cin>>c;
            a[i][j] = c-'0';
        }
    }

    c[0][0] = a[0][0];

    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            c[i][j] = c[i-1][j] + c[i][j-1] + a[i][j] - c[i-1][j-1];
        }
    }

    // for(i=1;i<=n;i++){
    //     for(j=1;j<=m;j++){
    //         cout<<c[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<endl;

    int ans = inf;

    for(int mask = 0;mask < (1LL<<n);mask++){
        int t[n+1] = {0};
        for(i=0;i<n;i++){
            t[i+1] = (mask&(1LL<<i) ? 1 : 0);
        }
        t[0] = -1;
        // for(i=1;i<=n;i++) cout<<t[i];

        vector<int> v;
        v.pb(0);
        for(i=1;i<n;i++){
            if(t[i] == 1){
                v.pb(i);
            }
        }
        v.pb(n);
        // cout<<" "; 
        // for(auto x:v) cout<<x<<" "; cout<<endl;

        int cnt = (int)v.size() - 2;
        vector<int> sm;
        int lt = 0;
        for(i=0;i<v.size();i++){
            sm.pb(0);
        }

        for(j=1;j<=m;j++){
            for(i=1;i<v.size();i++){
                sm[i] = c[v[i]][j] - c[v[i-1]][j] - c[v[i]][lt] + c[v[i-1]][lt];
            }

            int is = 0;

            for(i=1;i<v.size();i++){
                if(sm[i] > k){
                    is = 1;
                    break;
                }
            }

            if(is == 1){
                if(lt == j-1){
                    cnt = inf;
                    break;
                }
                else{
                    lt = j-1;
                    j--;
                    cnt++;
                }
            }
        }

        ans = min(ans , cnt);
        // cout<<mask<<" "<<cnt<<endl;
    }   

    cout<<ans<<endl;
}       


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

/*

*/

Measured memory_bytes: 384