using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.IO;
using System.Text;
using N = System.Int32;

public class Solver
{
    public void Solve()
    {
        N h = ri, w = ri, k = ri;
        string[] s = new string[h];
        for(int i = 0; i < h; i++) { s[i] = rs; }
        //カウント(c[i+1,j+1]で(1,1)~(i,j)の和)
        N[,] c = new N[h + 1, w + 1];
        for(int H = 0; H < h; H++)
        {
            for (int W = 0; W < w; W++)
            {
                c[H + 1, W + 1] = c[H + 1, W];
                if (s[H][W] == '1') c[H + 1, W + 1]++;
            }
            for (int W = 0; W < w; W++)
            {
                c[H + 1, W + 1] += c[H, W + 1];
            }
        }
        //h<=10なので多分横方向の切断はビット全探索が正解(てきとう)
        N hfrom = 0, wfrom = 0;
        bool b = false;
        bool[] cut = new bool[h - 1];
        N result = h + w, t = 0;
        for (int n = 0; n < 1 << (h - 1); n++)
        {
            t = 0;
            wfrom = 0;
            for(int i = 0; i < h - 1; i++)
            {
                cut[i] = (n >> i) % 2 == 1;
            }
            t += cut.Count(x => x);
            N j = 0;
            while (j < w)
            {
                hfrom = 0;
                b = false;
                for(int i = 0; i < h - 1; i++)
                {
                    if (cut[i])
                    {
                        b = c[hfrom, wfrom] - c[i + 1, wfrom] - c[hfrom, j + 1] + c[i + 1, j + 1] > k;
                        if (b) break;
                        hfrom = i + 1;
                    }
                }
                if (!b) b = c[hfrom, wfrom] - c[h, wfrom] - c[hfrom, j + 1] + c[h, j + 1] > k;
                if (b)
                {
                    if (wfrom == j)
                    {
                        t = h + w;
                        break;
                    }
                    t++;
                    wfrom = j;
                    j--;
                }
                j++;
            }
            result = Math.Min(result, t);
        }
        Write(result);
    }

    int ri { get { return sc.Integer(); } }
    long rl { get { return sc.Long(); } }
    double rd { get { return sc.Double(); } }
    string rs { get { return sc.Scan(); } }
    public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());

    /*
    private const N mod = 1000000007;
    N Reverse(N n) { return Pow(n, mod - 2); }
    N Mul(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; }
    N Pow(N n, N p) { N t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p >>= 1; } return q; }
    N PowUpper(N n, N b) { N p = 1; while (p <= n) { p *= b; } return p; }
    N Sign(N n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }
    N Abs(N n) { return (n > 0) ? n : -n; }
    N Gcd(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; }
    N Gcd(N a, N b) { return (a == 0) ? b : Gcd(b % a, a); }
    N Lcm(params N[] n) { N p = n[0]; for (N i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; }
    N Lcm(N a, N b) { return (a / Gcd(a, b) * b) % mod; }
    */
    void Write<T>(T t) { Console.WriteLine(t.ToString()); }
    void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
    void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
    void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}

static class Program
{
    static public void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}



public class StreamScanner
{
    public StreamScanner(Stream stream) { str = stream; }
    private readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public bool IsEndOfStream { get { return isEof; } }
    private byte read()
    {
        if (isEof) throw new EndOfStreamException();
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
    public char Char()
    {
        byte b = 0;
        do b = read();
        while (b < 33 || 126 < b);
        return (char)b;
    }
    public string Scan()
    {
        var sb = new StringBuilder();
        for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
            sb.Append(b);
        return sb.ToString();
    }
    public long Long()
    {
        long ret = 0; byte b = 0; var ng = false;
        do b = read();
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-') { ng = true; b = read(); }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
                return ng ? -ret : ret;
            else ret = ret * 10 + b - '0';
        }
    }
    public int Integer() { return (int)Long(); }
    public double Double() { return double.Parse(Scan()); }
}


Measured memory_bytes: 13376