using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var h = r[0].ToInt();
            var w = r[1].ToInt();
            var k = r[2].ToInt();
            var ls = new List<string>();
            for (int i = 0; i < h; i++)
            {
                var s = Read();
                ls.Add(s);
            }
            var group = new int[10][];
            for (int i = 0; i < 10; i++) group[i] = new int[1005];
            var INF = 100100101;
            var ans = INF;
            for (int div = 0; div < 1 << (h - 1); div++)
            {
                var g = 0;
                var gId = new List<int>();
                for (int i = 0; i < h; i++)
                {
                    gId.Add(g);
                    if ((div >> i & 1) == 1)
                    {
                        g++;
                    }
                }
                g++;
                for (int i = 0; i < g; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        group[i][j] = 0;
                    }
                }
                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        group[gId[i]][j] += ls[i][j] == '1' ? 1 : 0;
                    }
                }

                var ok = true;
                for (int i = 0; i < g; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        if (group[i][j] > k) ok = false;
                    }
                }
                if (!ok) continue;

                int num = g - 1;
                var now = new int[g];

                var add = new Predicate<int>(x =>
                {
                    for (int i = 0; i < g; i++)
                    {
                        now[i] += group[i][x];
                    }
                    for (int i = 0; i < g; i++)
                    {
                        if (now[i] > k) return false;
                    }
                    return true;
                });

                for (int j = 0; j < w; j++)
                {
                    if (!add(j))
                    {
                        num++;
                        now = new int[g];
                        add(j);
                    }
                }
                ans = Math.Min(ans, num);
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 13268