package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var S [10][1000]int
var vsplit [10]int
var hsplit [1000]int
var minsplits int

func main() {
	io := NewIo()
	defer io.Flush()

	H := io.NextInt()
	W := io.NextInt()
	K := io.NextInt()

	// fmt.Printf("%d %d %d\n", H, W, K)
	for i := 0; i < H; i++ {
		str := io.Next()
		for j := 0; j < W; j++ {
			S[i][j] = int(str[j]) - 48
		}
		// fmt.Printf("%v\n", S[i][0:W])
	}

	for i := 0; i < H; i++ {
		count := 0
		for j := 0; j < W; j++ {
			count += S[i][j]
		}
		// fmt.Printf("R%d %v\n", i, count)
	}

	for i := 0; i < W; i++ {
		count := 0
		for j := 0; j < H; j++ {
			count += S[j][i]
		}
		// fmt.Printf("C%d %v\n", i, count)
	}

	minsplits = 2000
	var hsplitarray [10]int
	for i := 0; i < (1 << uint(H-1)); i++ {
		hsplitarray[0] = 1
		for j := 1; j < H; j++ {
			hsplitarray[j] = 0
		}
		cursor := 0
		for j := 0; j < H-1; j++ {
			if uint(i>>uint(j))%2 > 0 { // split here
				cursor = j + 1
			}
			hsplitarray[cursor]++
		}
		// fmt.Printf("%v\n", hsplitarray)
		// hsplit points H-1
		splits := greedSplit2(hsplitarray[0:H], H, W, K)
		if splits < minsplits {
			minsplits = splits
		}
	}
	fmt.Printf("%v\n", minsplits)
	os.Exit(0)

	greedSplit(0, H, W, K)
	greedSplit(0, H-1, W, K)
	greedSplit(0, H-2, W, K)
	os.Exit(1)

	vsplit[0] = 0
	hsplit[0] = 0
	vsplit[1] = H / 2
	hsplit[1] = W / 2
	vend := 0
	hend := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			if i == 1 {
				vend = H
			} else {
				vend = vsplit[i+1]
			}
			if j == 1 {
				hend = W
			} else {
				hend = hsplit[j+1]
			}
			fmt.Printf("%d %d %d %d %d %d\n", i, j, vsplit[i], hsplit[j], vend-vsplit[i], hend-hsplit[j])
			fmt.Printf("%d %d %d\n", i, j, countWhite(vsplit[i], hsplit[j], vend-vsplit[i], hend-hsplit[j], K))
		}
	}

	fmt.Printf("%d\n", countWhite(0, 0, H, W, K))
}

func countWhite(r, c, h, w, k int) int {
	count := 0
	for i := r; i < h; i++ {
		for j := c; j < w; j++ {
			count += S[i][j]
		}
	}
	return count
}

// input, maximum number of a single block
// return nr of splits
func greedSplit(hstart, hlen, width, max int) int {
	count := 0
	splits := 0
	for i := 0; i < width; i++ {
		hcount := 0
		for j := hstart; j < hstart+hlen; j++ {
			hcount += S[j][i]
		}
		if hcount > max {
			// single column has >max 1s
			return -1
		}
		if hcount+count > max {
			// need to start new block here
			count = 0
			splits++
		}
		count += hcount
		fmt.Printf("%v, %v, %v, %v\n", i, hcount, count, splits)
	}
	return splits
}

// input, maximum number of a single block
// return nr of splits
func greedSplit2(split []int, height, width, max int) int {
	var count [10]int
	hsplits := -1
	vsplits := 0

	for i := 0; i < height; i++ {
		count[i] = 0
		if split[i] > 0 {
			hsplits += 1
		}
	}

	if minsplits < hsplits {
		return 99999
	}

	var hcount [10]int
	for i := 0; i < width; i++ {
		for j := 0; j < height; j++ {
			hcount[j] = 0
		}
		vsplit := 0
		for k := 0; k < height; k++ {
			if split[k] == 0 {
				continue
			}
			for j := k; j < k+split[k]; j++ {
				hcount[k] += S[j][i]
			}
			if hcount[k] > max {
				// single column has >max 1s, so this block layout never be a valid one
				// fmt.Printf("case1 %v, %v\n", k, split[k])
				return 9990
			}
			// fmt.Printf("__ %v, %v, %v, %v, %v\n", i, k, split[k], hcount[k], count[k])
			if hcount[k]+count[k] > max {
				// fmt.Printf("cut vsplit at %v, %v\n", i, k)
				vsplit = 1
			}
		}
		if vsplit == 1 {
			vsplits++
			for k := 0; k < height; k++ {
				if split[k] == 0 {
					continue
				}
				count[k] = hcount[k]
				// fmt.Printf("vSPLIT %v, %v, %v, %v, %v\n", i, k, hcount[k], count[k], vsplits)
			}
		} else {
			for k := 0; k < height; k++ {
				if split[k] == 0 {
					continue
				}
				count[k] += hcount[k]
			}
			// fmt.Printf("%v, %v, %v, %v, %v\n", i, k, hcount[k], count[k], vsplits)
		}
	}
	// fmt.Printf("%v %v\n", hsplits, vsplits)
	return hsplits + vsplits
}

// Libraries

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo
func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

// Flush
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextFloat
func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

// PrintLn
func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

// Printf
func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

// PrintIntLn
func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

// PrintStringLn
func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

// Log
func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// direct calculation of combination
// n, m should be "small"
func combination(n, m int) int {
	if m > n {
		return 0
	} else if m == n || m == 0 {
		return 1
	} else {
		res := 1
		for i := 0; i < m; i++ {
			res *= (n - i)
		}
		for i := 1; i <= m; i++ {
			res /= i
		}
		return res
	}
}

// caluclate combination modulo based on Lucas theorem
func lucas(n, m, p int) int {
	ntemp := n
	mtemp := m
	res := 1
	for i := 0; i < 100; i++ {
		// fmt.Printf("ntemp: %d\n", ntemp)
		nreminder := ntemp % p
		ntemp = ntemp / p
		mreminder := mtemp % p
		mtemp = mtemp / p
		res = res * (combination(nreminder, mreminder) % p)
		if ntemp == 0 {
			break
		}
	}
	return res % p
}

func combMod(n, m, p int) int {
	return lucas(n, m, p)
}


Measured memory_bytes: 640