/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int h, w, K;
    cin >> h >> w >> K;

    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }

    vector<vector<int>> hsum(w, vector<int>(h + 1, 0));
    //cout << "---" << endl;
    rep(i, w){
        rep(j, h){
            if(s[j][i] == '1'){
                hsum[i][j + 1] += hsum[i][j] + 1;
            } else {
                hsum[i][j + 1] += hsum[i][j];
            }
        }
    }
    // rep(i, h + 1){
    //     rep(j, w){
    //         cout << hsum[j][i];
    //     }
    //     cout << endl;
    // }
    bool dflag = false;
    int ans = 1e9;
    for(int bit = 0; bit < (1 << h - 1); bit++){
        vector<int> cut;
        for(int i = 0; i < h - 1; i++){
            if(bit & (1 << i)){
                cut.push_back(i);
            }
        }
        //if(bit == 3) dflag = true;
        int ma = 0;
        vector<vector<int>> sum(cut.size() + 1, vector<int>(w + 1, 0));
        int lastcut = 0;
        int tmpans = 0;
        bool fff = false;
        for(int i = 0; i < w; i++){
            int now = 0;
            bool c = false;
            for(int j = 0; j < cut.size(); j++){
                int tmpsum = 0;
                for(int jj = now; jj <= cut[j]; jj++){
                    if(s[jj][i] == '1') tmpsum++;
                }
                sum[j][i + 1] = sum[j][i] + tmpsum;
                ma = max(ma,  sum[j][i + 1] - sum[j][lastcut]);
                if(dflag) cout << j << " " << i + 1 << " " << sum[j][i + 1] << " lst " << lastcut << " " << sum[j][lastcut] << endl;
                if(sum[j][i + 1] - sum[j][lastcut] > K){
                    c = true;
                }
                now = cut[j] + 1;
            }
            int tmpsum = 0;
            for(int jj = now; jj < h; jj++){
                if(s[jj][i] == '1') tmpsum++;
            }
            sum[cut.size()][i + 1] = sum[cut.size()][i] + tmpsum;
            ma = max(ma, sum[cut.size()][i + 1] - sum[cut.size()][lastcut]);
            if(dflag) cout << i + 1 << " f " <<sum[cut.size()][i + 1] << endl;
            if(sum[cut.size()][i + 1] - sum[cut.size()][lastcut] > K){
                c = true;
            }
            if(c){
                //cout << "ma" << ma << endl;
                if(abs(lastcut - i) < 1){
                    fff = true;
                    break;
                }
                lastcut = i;
                tmpans++;
                if(dflag) cout << "H" << endl;
            }
        }
        if(fff) continue;
        //if(tmpans + __builtin_popcount(bit) == 3) cout << "bit"<< bit << endl;
        ans = min(ans, tmpans + __builtin_popcount(bit));
        dflag = false;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384