#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for (auto &s : S) cin >> s;
    
    int ans = 1e9;
    for (int bit = 0; bit < 1 << (H - 1); bit++) {
        int cut = 0;
        vector<int> div(H);
        for (int i = 0; i < H; i++) {
            div.at(i) = cut;
            if (bit >> i & 1) cut++;
        }
        vector<int> cnt(cut + 1);
        for (int w = 0; w < W; w++) {
            vector<int> tmp(cut + 1);
            bool add = false;
            for (int h = 0; h < H; h++) {
                int d = div.at(h);
                if (S.at(h).at(w) == '1') cnt.at(d)++, tmp.at(d)++;
                if (cnt.at(d) > K) add = true;
                if (tmp.at(d) > K) goto NG;
            }
            if (add) cut++, cnt = tmp;
        }
        ans = min(ans, cut);
        NG:;
    }
    cout << ans << "\n";
}