#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint H, W, K; cin >> H >> W >> K;
    vec<string> chocolate(H);
    range(i, 0, H) cin >> chocolate.at(i);
    vec<vec<lint>> pref_sum_num_whites_col(H, vec<lint>(W, 0));
    range(j, 0, W) {
        pref_sum_num_whites_col.at(0).at(j) = chocolate.at(0).at(j) == '1';
        range(i, 1, H)
            pref_sum_num_whites_col.at(i).at(j) =
                pref_sum_num_whites_col.at(i - 1).at(j) + (chocolate.at(i).at(j) == '1');
    }
    lint ans = (H - 1) * (W - 1);
    range(bits, 0, 1LL << (H - 1)) {
        lint num_splits_row = 0;
        lint num_splits_col = 0;
        range(i, 0, H - 1) num_splits_row += ((bits >> i) & 1);
        vec<lint> cuml_num_white_col(num_splits_row + 1, 0);
        bool one_block_exceeds_K = false;
        range(j, 0, W) {
            vec<lint> cur_num_white_col;
            lint num_whites = 0;
            range(i, 0, H) {
                num_whites += chocolate.at(i).at(j) == '1';
                if (i != H - 1 and ((bits >> i) & 1)) {
                    cur_num_white_col.emplace_back(num_whites);
                    num_whites = 0;
                }
            }
            cur_num_white_col.emplace_back(num_whites);
            assert(cur_num_white_col.size() == num_splits_row + 1);
            // cout << cur_num_white_col << "\n";
            range(i, 0, num_splits_row + 1) if (cur_num_white_col.at(i) > K) {
                one_block_exceeds_K = true;
                break;
            }
            if (one_block_exceeds_K) break;

            range(i, 0, num_splits_row + 1) {
                if (cur_num_white_col.at(i) + cuml_num_white_col.at(i) > K) {
                    cuml_num_white_col = cur_num_white_col;
                    num_splits_col += 1;
                    break;
                } else cuml_num_white_col.at(i) += cur_num_white_col.at(i);
            }
            // cout << cuml_num_white_col << "\n"; 
        }
        // cout << bits << " " << num_splits_row << " " << num_splits_col <<  "\n";
        if (!one_block_exceeds_K)
            ans = min(ans, num_splits_row + num_splits_col);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 512