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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int h, w, k;
    cin >> h >> w >> k;
    vector < vector <int> > s(h, vector <int> (w));
    int cnt = 0;

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char c; cin >> c;
            s[i][j] = c - '0';
            if(s[i][j]) cnt++;
        }
    }

    if(cnt <= k) {
        cout << 0 << '\n';
        return;
    }
    
    int ans = h-1 + w-1;

    for(int i = 1; i < (1 << h); i++) {
        if(i & 1) continue;                        // exclude top cut

        vector <int> rows;
        for(int j = 0; j < h; j++) {
            if(i & (1 << j)) rows.push_back(j);
        }
        int szz = rows.size();
        int cuts = szz;
        vector <int> whites(szz+1, 0);
        bool within = 0, first = 1;

        for(int j = 0; j < w; j++) {
            bool ok = 1;
            int r = 0;
            for(int ind = 0; ind < szz; ind++) {
                if(ind) r = rows[ind-1];

                while(r <= rows[ind]-1) {
                    if(s[r][j]) {
                        whites[ind]++;
                        if(whites[ind] > k) {
                            ok = 0;
                            if(first) within = 1;
                        }
                    }
                    r++;
                }
            }

            r = rows[szz-1];
            while(r < h) {
                if(s[r][j]) {
                    whites[szz]++;
                    if(whites[szz] > k) {
                        ok = 0;
                        if(first) within = 1;
                    }
                }
                r++;
            }

            if(! ok) {
                if(within) break;
                else {
                    cuts++;
                    j--;
                    first = 1;
                    fill(whites.begin(), whites.end(), 0);
                }
            }
            else {
                first = 0;
            }
        }
        if(! within) ans = min(ans, cuts);
    }
    cout << ans << '\n';
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 384