#region memo
/* 
 * 偶奇が大切な問題では、偶数番目と奇数番目を分けて配列に入れる
 * 文字列の処理は遅い。char[]で計算して、最後にstringにする
 * (char)0 は、0'\0'となる
 * (char)0は48
 * 制約から解法が決まる
 */
#endregion

using System.Collections;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        int[] HWK = ReadInts;
        int H = HWK[0];
        int W = HWK[1];
        int K = HWK[2];
        string[] choko = new string[H];
        for (int i = 0; i < H; i++)
        {
            choko[i] = ReStr;
        }
        int ans = 1010;



        //縦方向にビット全探索
        for (int i = 0; i < 2<<H-1; i++)//512
        {
            bool can = true;

            bool[] verCuts = new bool[W - 1];
            bool[] wCuts = new bool[H - 1];
            int wCutCount = 0;
            int hoCutCount = 0;


            for (int j = 0; j < H-1; j++)
            {
                wCuts[j] = (i >> j & 1) == 1;
                if (wCuts[j]) hoCutCount++;
            }
            int[] whiteCounts = new int[hoCutCount+1];

            //横方向に貪欲法
            int currentDomain = 0;
            for (int w = 0; w < W; w++)//1000
            {

                can = true;
                for (int h = 0; h < H; h++)//10
                {
                    if (h == 0)
                    {
                        currentDomain = 0;
                    }
                    else
                    {
                        if (wCuts[h - 1])
                        {
                            currentDomain++;
                        }
                    }
                    if (choko[h][w] == '1')
                    {
                        whiteCounts[currentDomain]++;
                        if (whiteCounts[currentDomain] > K)
                        {
                            wCutCount++;
                            if (w == 0 || verCuts[w - 1])
                            {
                                can = false;
                            }
                            else
                            {
                                whiteCounts = new int[hoCutCount + 1];
                                h = -1;
                                verCuts[w - 1] = true;
                            }
                        }
                    }
                    if (!can) break;
                }
                if (!can) break;
            }

            if(can)ans = Min(ans,wCutCount + hoCutCount);
        }


        WriteLine(ans);
        ReadLine();
    }

    struct Vector2Int
    {
        public Vector2Int(int x, int y)
        {
            X = x;
            Y = y;
        }
        public int X;
        public int Y;
        public double Magnitude => Math.Sqrt(X * X + Y * Y);

        public static Vector2Int zero => new Vector2Int(0, 0);
        public static Vector2Int u => new Vector2Int(0, 1);
        public static Vector2Int r => new Vector2Int(1, 0);
        public static Vector2Int d => new Vector2Int(0, -1);
        public static Vector2Int l => new Vector2Int(-1, 0);
        public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l };

        public static Vector2Int operator +(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X + b.X, a.Y + b.Y);
        }
        public static Vector2Int operator -(Vector2Int a, Vector2Int b)
        {
            return new Vector2Int(a.X - b.X, a.Y - b.Y);
        }
        public static bool operator ==(Vector2Int a, Vector2Int b)
        {
            return a.X == b.X && a.Y == b.Y;
        }
        public static bool operator !=(Vector2Int a, Vector2Int b)
        {
            return a.X != b.X || a.Y != b.Y;
        }
        public static Vector2Int operator *(Vector2Int v, int n)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
        public static Vector2Int operator *(int n, Vector2Int v)
        {
            return new Vector2Int(v.X * n, v.Y * n);
        }
    }
    struct Vector3Int
    {
        public Vector3Int(int x, int y, int z)
        {
            X = x;
            Y = y;
            Z = z;
        }
        public int X;
        public int Y;
        public int Z;

        public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z);

        public static Vector3Int zero => new Vector3Int(0, 0, 0);
        public static Vector3Int u => new Vector3Int(0, 1, 0);
        public static Vector3Int r => new Vector3Int(1, 0, 0);
        public static Vector3Int d => new Vector3Int(0, -1, 0);
        public static Vector3Int l => new Vector3Int(-1, 0, 0);

        public static Vector3Int operator +(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
        }
        public static Vector3Int operator -(Vector3Int a, Vector3Int b)
        {
            return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
        }
        public static bool operator ==(Vector3Int a, Vector3Int b)
        {
            return a.X == b.X && a.Y == b.Y && a.Z == b.Z;
        }
        public static bool operator !=(Vector3Int a, Vector3Int b)
        {
            return a.X != b.X || a.Y != b.Y || a.Z != b.Z;
        }
        public static Vector3Int operator *(Vector3Int v, int n)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
        public static Vector3Int operator *(int n, Vector3Int v)
        {
            return new Vector3Int(v.X * n, v.Y * n, v.Z * n);
        }
    }

    #region Reader
    static Vector2Int ReVec2Int { get {
            string[] s = Console.ReadLine().Split(' ');
            return new Vector2Int(int.Parse(s[0]), int.Parse(s[1]));
        } }
    static Vector2Int[] ReVec2Ints(int n)
    {
        List<Vector2Int> list = new List<Vector2Int>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Vector2Int(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static string ReStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static long[,] ReLongMatrix(int r, int c)
    {
        var mat = new long[r, c];
        for (int i = 0; i < r; ++i)
        {
            var x = ReLongs;
            for (int j = 0; j < c; ++j)
            {
                mat[i, j] = x[j];
            }
        }
        return mat;
    }
    static Tuple<string, string>[] ReTupleStr(int n)
    {
        List<Tuple<string, string>> list = new List<Tuple<string, string>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadStrs;
            list.Add(new Tuple<string, string>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<long, long>[] ReTupleLong(int n)
    {
        List<Tuple<long, long>> list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReLongs;
            list.Add(new Tuple<long, long>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<int, int>[] ReTupleInt(int n)
    {
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadInts;
            list.Add(new Tuple<int, int>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<double, double>[] ReTupleDouble(int n)
    {
        List<Tuple<double, double>> list = new List<Tuple<double, double>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReLongs;
            list.Add(new Tuple<double, double>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M)
    {
        Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
        for (int i = 0; i <= N; ++i)
        {
            dict.Add(i, new HashSet<int>());
        }
        for (int i = 0; i < M; ++i)
        {
            var ab = ReadInts;
            dict[ab[0]].Add(ab[1]);
            dict[ab[1]].Add(ab[0]);
        }
        return dict;
    }
    #endregion
}

Measured memory_bytes: 13396