#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W, K;
    cin >> H >> W >> K;
    VEC(string) Bar(H);
    READVEC(Bar);

    int ret = H + W - 2;
    FOR(mask, 0, 1 << (H - 1)) {
        VEC(int) hbars;
        FOR(i, 0, H - 1)
            if (mask & (1 << i))
                hbars.push_back(i);

        VEC(Pii) ranges;
        if (hbars.empty()) {
            ranges.push_back(Pii(0, H - 1));
        } else {
            ranges.push_back(Pii(0, hbars[0]));
            FOR(i, 0, hbars.size() - 1) {
                ranges.push_back(Pii(hbars[i] + 1, hbars[i + 1]));
            }
            if (hbars.back() + 1 < H) {
                ranges.push_back(Pii(hbars.back() + 1, H - 1));
            }
        }

        const int N = ranges.size();
        VEC(VEC(int)) Grid(N, VEC(int)(W, 0));
        VEC(int) Sums(N, 0);
        int cuts = 0;
        FOR(i, 0, N) {
            int start = ranges[i].first, end = ranges[i].second;
            FOR(j, 0, W) {
                FOR(k, start, end + 1)
                    if (Bar[k][j] == '1')
                        Grid[i][j]++;

                if (Grid[i][j] > K) {
                    goto next;
                }
            }
        }

        // We computed the new N x W grid.
        // Greedily choose the vertical cuts.
        FOR(i, 0, N)
            Sums[i] = Grid[i][0];

        FOR(j, 1, W) {
            bool good = true;
            FOR(i, 0, N)
                if (Sums[i] + Grid[i][j] > K) {
                    good = false;
                    break;
                }

            if (good) {
                FOR(i, 0, N)
                    Sums[i] += Grid[i][j];
            } else {
                cuts++;
                FOR(i, 0, N)
                    Sums[i] = Grid[i][j];
            }
        }

        ret = min<int>(ret, hbars.size() + cuts);
next:;
    }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 384