#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int H,W,K; cin >> H >> W >> K;
    vector<string> S(1010);
    ll mi = 1e9;
    for(int y=0;y<H;y++) cin >> S[y];
    
    for(ll bit=0;bit<(1<<(H-1));++bit){
        vector<ll> seg(12,0);
        ll num = 0;
        for(int i=0;i<H;++i){
            seg[i] = num;
            if(bit&(1<<i)) num++;
        }
        ll res = __builtin_popcount(bit);
        vector<ll> count(12);
        for(int x=0;x<W;x++){
            for(int y=0;y<H;y++){
                if(S[y][x] == '1') count[seg[y]]++;
            }
            for(int i=0;i<num+1;i++){
                if(count[i]>K){
                    res++;
                    for(int y=0;y<num+1;++y) count[y] = 0;
                    for(int y=0;y<H;y++) if(S[y][x] == '1') count[seg[y]]++;
                    break;
                }
            }
            for(int i=0;i<num+1;i++)if(count[i]>K) res=1e9;
        }
        mi = min(mi,res);
    }
    cout << mi << endl;
}