#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define VI vector<int>
#define VII vector<pair<int, int>>
#define PII pair<int, int>
#define MP make_pair
// #define log(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define log(fmt, ...)
// #define check(...) assert(##__VA_ARGS__)
#define check(...)

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int h, w, k;
    cin >> h >> w >> k;  // h <= 10
    string s[h];
    int pre[h + 1][w];
    log("\n");
    rep(i, 0, h) {
        cin >> s[i];
    }
    rep(j, 0, w) {
        pre[h][j] = 0;
        repi(i, h - 1, 0) {
            pre[i][j] = pre[i + 1][j] + (s[i][j] == '1' ? 1 : 0);
        }
    }
    rep(i, 0, h + 1) {
        rep(j, 0, w) {
            log("%d ", pre[i][j]);
        }
        log("\n");
    }

    // exit(0);

    int ans = 99999999;
    // 枚举横切，贪心纵切
    // h行，最多切h-1刀。
    rep(i, 0, 1 << (h - 1)) {
        vector<int> rows;
        rows.push_back(0);
        rep(row, 0, h - 1) {  // 在row的下边切
            if (((1 << row) & i) > 0) {
                rows.push_back(row + 1);
            }
        }
        rows.push_back(h);
        log("rows.size = %lu\n", rows.size());
        for (auto x : rows) {
            log("%d ", x);
        }
        log("\n");
        int ans1 = rows.size() - 2;
        log("ans1=%d\n", ans1);
        int n_rows = rows.size() - 1;
        log("n_rows=%d\n", n_rows);
        int acc[n_rows];
        fill_n(acc, n_rows, 0);
        int ans2 = 0;
        rep(col, 0, w) {  // 如果要切，在col的左边切
            bool good = true;
            bool impossible = false;
            rep(j, 0, n_rows) {
                int inc = pre[rows[j]][col] - pre[rows[j + 1]][col];
                if (inc > k) {
                    impossible = true;
                    break;
                }
                log("pre[%d][%d]=%d\n", rows[j], col, pre[rows[j]][col]);
                log("pre[%d][%d]=%d\n", rows[j + 1], col, pre[rows[j + 1]][col]);
                log("[%d,%d)=%d\n", rows[j], rows[j + 1], inc);
                if (acc[j] + inc > k) {
                    good = false;
                    break;
                }
            }
            if (impossible) {
                ans2 = 99999999;
                break;
            }
            if (good) {
                rep(j, 0, n_rows) {
                    int inc = pre[rows[j]][col] - pre[rows[j + 1]][col];
                    acc[j] += inc;
                }
            } else {
                ans2++;
                rep(j, 0, n_rows) {
                    int inc = pre[rows[j]][col] - pre[rows[j + 1]][col];
                    acc[j] = inc;
                }
            }
            log("col=%d\n", col);
            rep(j, 0, n_rows) {
                log("%d ", acc[j]);
            }
            log("\n");
        }
        log("ans2=%d\n", ans2);
        ans = min(ans, ans1 + ans2);
        if (ans == 0) {
            log("status=%d\n", i);
        }
    }
    cout << ans;
}


Measured memory_bytes: 384