#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e & 1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) {
        return 0;
    }
    if (n == r || r == 0) {
        return 1;
    }
    r = min(r, n - r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n - i + 1)) / (i);
    }
    return ans;
}

ll nCr(tuple<ll, ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n + k - 1, k);
}

template <typename T>
void print(T v) {
    cout << v << " ";
}

template <typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll>> S(h, vector<ll>(w, 0));
    vector<string> S_(h);
    for (int i = 0; i < h; ++i) {
        cin >> S_[i];
        for (int j = 0; j < w; ++j) {
            S[i][j] = S_[i][j] - '0';
        }
    }

    ll minCut = (h - 1) * (w - 1);

    for (ll i = 0; i < (1LL << (h - 1)); ++i) {
        bool isValid = true;
        ll cut = __builtin_popcountll(i);
        ll last_pos = 0;
        ll next_pos = 0;
        vector<vector<ll>> Wm;
        do {
            next_pos = h - 1;
            for (int it = last_pos; it < h; ++it) {
                if ((i >> it) & 1) {
                    next_pos = it;
                    break;
                }
            }

            vector<ll> W(w, 0);
            for (int l = last_pos; l <= next_pos; ++l) {
                for (int j = 0; j < w; ++j) {
                    W[j] += S[l][j];
                }
            }
            Wm.push_back(W);
            last_pos = next_pos + 1;
        } while (isValid && next_pos != h - 1);

        vector<ll> runCount(Wm.size(), 0);
        for (int j = 0; j < w; ++j) {
            bool isReq = false;
            for (int l = 0; l < Wm.size(); ++l) {
                if (Wm[l][j] + runCount[l] > k) {
                    isReq = true;
                    break;
                } else {
                    isReq = false;
                }
            }
            if (isReq) {
                ++cut;
                for (int l = 0; l < Wm.size(); ++l) {
                    runCount[l] = Wm[l][j];
                    if (runCount[l] > k) {
                        isValid = false;
                    }
                }
            } else {
                for (int l = 0; l < Wm.size(); ++l) {
                    runCount[l] += Wm[l][j];
                }
            }
        }
        for (int l = 0; l < Wm.size(); ++l) {
            if (runCount[l] > k) {
                isValid = false;
            }
        }

        if (isValid) {
            minCut = min(minCut, cut);
        }
    }

    cout << minCut << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef D_LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif

    solve();

    return 0;
}

Measured memory_bytes: 384