using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{
    private int H, W, K;
    private string[] S;

    public void Solve()
    {
        var sc = new Scanner();
        H = sc.NextInt();
        W = sc.NextInt();
        K = sc.NextInt();
        S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = sc.Next();
        }

        int ans = int.MaxValue;
        int l = 1 << (H - 1);
        for (int i = 0; i < l; i++)
        {
            ans = Math.Min(ans, Cnt(i));
            //Console.WriteLine(i);
        }

        Console.WriteLine(ans);
    }

    int Cnt(int l)
    {
        int res = 0;
        List<int> cut = new List<int>();
        for (int i = 0; i < H - 1; i++)
        {
            if ((l & (1 << i)) > 0)
            {
                res++;
                cut.Add(i + 1);
            }
        }


        cut.Add(H);

        // j< cut[i]が追加される
        var white = new int[cut.Count];
        for (int j = 0; j < W; j++)
        {
            int index = 0;
            for (int i = 0; i < H; i++)
            {
                if (i >= cut[index]) index++;
                if (S[i][j] == '1') white[index]++;
            }

            if (white.Any(num => num > K))
            {
                res++;
                white = new int[cut.Count];
                index = 0;
                for (int i = 0; i < H; i++)
                {
                    if (i >= cut[index]) index++;
                    if (S[i][j] == '1') white[index]++;
                }

                if (white.Any(num => num > K))
                {
                    return int.MaxValue;
                }
            }
        }

        return res;
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 17352