import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int H, W, K;
    scan(H, W, K);
    auto s = iota(H).map!(i => readln.chomp).array;

    auto b = new int[][](H, W);
    foreach (i ; 0 .. H) {
        b[i] = s[i].map!(ch => ch - '0').array.to!(int[]);
    }

    auto c = new int[][](H + 1, W + 1);
    foreach (i ; 1 .. H + 1) {
        foreach (j ; 1 .. W + 1) {
            c[i][j] = c[i-1][j] + c[i][j-1] - c[i-1][j-1] + b[i-1][j-1];
        }
    }

    // [i1, i2) * [j1, j2) の累積和
    int csum(int i1, int j1, int i2, int j2) {
        auto res = c[i2][j2] - c[i1][j2] - c[i2][j1] + c[i1][j1];
        assert(res >= 0);
        return res;
    }

    int solve(int[] kgr) {
        int res;
        auto m = kgr.length.to!int - 1;
        assert(m >= 0);
        auto sm = new int[](m);

        foreach (j ; 0 .. W) {
            foreach (i ; 0 .. m) {
                auto white = csum(kgr[i], j, kgr[i + 1], j + 1);
                sm[i] += white;
            }

            if (sm.any!(smi => smi > K)) {
                res++;
                foreach (i ; 0 .. m) {
                    auto white = csum(kgr[i], j, kgr[i + 1], j + 1);
                    sm[i] = white;
                    if (sm[i] > K) {
                        return inf;
                    }
                }
            }
        }

        return res;
    }

    int ans = inf;

    foreach (set ; 0 .. 1 << (H - 1)) {
        int tmp;

        int[] kgr = [0];
        foreach (i ; 0 .. H - 1) if (set & 1 << i) {
            kgr ~= i + 1;
            tmp++;
        }
        kgr ~= H;
        debug {
            writeln(kgr);
        }

        tmp += solve(kgr);
        chmin(ans, tmp);
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}
