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

/////////////////////////
#ifdef DEBUG
#define DEB
#define dump(...)                                                       \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                     \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \
            << endl                                                     \
            << "    ",                                                  \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

#define DUMPOUT cerr
#define LINE(v)                                       \
    os << "{";                                        \
    for (auto itr = begin(v); itr != end(v); itr++) { \
        os << *itr;                                   \
        itr++;                                        \
        if (itr != end(v)) os << ", ";                \
        itr--;                                        \
    }                                                 \
    os << "}"

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    LINE(vec);
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &mat) {
    int len = mat.size();
    os << "{" << endl;
    for (int i = 0; i < len; ++i) {
        os << "     " << mat[i] << endl;
    }
    os << "    }";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    LINE(map_var);
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set_var) {
    LINE(set_var);
    return os;
}
/////////////////////////

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    vector<vector<int>> a(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '1') a[i][j] = 1;
        }
    }
    int ans = 1e9;
    for (int b = 0; b < 1 << (h - 1); b++) {
        int cnt = __builtin_popcount(b);
        int m = 0;
        vector<vector<int>> cs(h + 1, vector<int>(w + 1, 0));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cs[i + 1][j] = a[i][j];
                if (i > 0 && ~b >> (i - 1) & 1) cs[i + 1][j] += cs[i][j];
                m = max(m, cs[i + 1][j]);
            }
        }
        if (m > k) continue;
        for (int j = 0; j < w; j++) {
            m = 0;
            for (int i = 0; i < h; i++) {
                m = max(m, cs[i + 1][j] + cs[i + 1][j + 1]);
            }
            if (m <= k) {
                for (int i = 0; i < h; i++) cs[i + 1][j + 1] += cs[i + 1][j];
            } else {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384