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

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto K = s[2];
    auto A = iota(H).map!(_ => readln.chomp).array;

    int ans = 1 << 29;
    auto cnt = new int[](H);
    auto cnt2 = new int[](H);

    outer: foreach (mask; 0..1<<(H-1)) {
        int tmp = mask.popcnt;
        cnt[] = 0;
        cnt2[] = 0;
        foreach (j; 0..W) {
            int p = 0;
            bool flag = false;
            foreach (i; 0..H) {
                cnt2[p] += A[i][j] == '1';
                if (cnt2[p] > K) continue outer;
                if (cnt[p] + cnt2[p] > K) flag = true;
                if (mask & (1 << i)) p += 1;
            }
            if (flag) {
                tmp += 1;
                foreach (i; 0..cnt.length) {
                    cnt[i] = cnt2[i];
                }
            } else {
                foreach (i; 0..cnt.length) {
                    cnt[i] += cnt2[i];
                }
            }
            cnt2[] = 0;
        }
        ans = min(ans, tmp);
    }

    ans.writeln;
}