import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;
void main()
{
    immutable buf = readln.chomp.split.to!(size_t[]);
    bool[][] chocolate;
    foreach (i; 0..buf[0])
        chocolate ~= readln.chomp.map!(_=>_=='1').array;
    auto answer = int.max;
    foreach (p; 0..1<<(chocolate.length - 1))
        answer = answer.min(solve(chocolate, p.toUpperLower(buf[0]), buf[2]));
    answer.writeln;
}

size_t[] toUpperLower(size_t p, size_t h)
{
    auto ret = [size_t(0)];
    foreach (i; 1..h)
    {
        if (p & 1) ret ~= i;
        p >>= 1;
    }
    return ret ~ h;
}

int solve(in bool[][] chocolate, size_t[] pattern, size_t k)
{
    stderr.writefln("pattern: %(%d..%)", pattern);
    size_t left;
    int cut;
    foreach (right; 1..chocolate[0].length+1) // right
    {
        if (chocolate.ng(pattern, left, right, k))
        {
            if (left == right - 1)
                return int.max;
            cut += 1;
            stderr.writefln("cut: %d..%d", left, right-1);
            left = right - 1;
        }
    }
    return cut + pattern.length - 2;
}

bool ng(in bool[][] chocolate, size_t[] pattern, size_t left, size_t right, size_t k)
{
    foreach (i; 0..pattern.length-1)
    {
        size_t s;
        foreach (j; pattern[i]..pattern[i+1])
            if (k < (s += chocolate[j][left..right].sum))
                return true;
    }
    return false;
}
