from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

import sys,bisect,math,itertools,fractions

from decimal import Decimal

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,m,K = inpl()

s = [eval(input()) for _ in range(n)]

res = INF

for pat in itertools.product([0,1], repeat=n-1):

    pat = list(pat) + [0]

    group = []

    tmp = []

    for i,j in enumerate(pat):

        tmp += [i]

        if j or i == n-1:

            group += [tmp]

            tmp = []

    

    ln = len(group)

    white = [[0]*ln for _ in range(m)]

    ccc = set()

    cnt = pat.count(1) 

    ok = True

    for i in range(m):

        for j,z in enumerate(group):

            for k in z:

                if s[k][i] == '1':

                    white[i][j] += 1

            if max(white[i]) > K:

                ok = False

                break

    if not ok: continue

    

    now = [0] * ln

    for i in range(m):

        ok = True

        for j in range(ln):

            if now[j] + white[i][j] > K:

                ok = False

                break

        if ok:

            for j in range(ln):

                now[j] += white[i][j]

        else:

            cnt += 1

            for j in range(ln):

                now[j] = white[i][j]

    res = min(res, cnt)

print(res)
from collections import Counter,defaultdict,deque

from heapq import heappop,heappush

from bisect import bisect_left,bisect_right 

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



h,w,k = inpl()

s = [list(eval(input())) for _ in range(h)]

res = INF

for yoko in itertools.product([0,1], repeat=(h-1)):

    # 0:uncut 1:cut

    ln = sum(yoko)

    gr = [[] for _ in range(ln+1)] 

    gr[0].append(0)

    ind = 0

    for i in range(1,h):

        if yoko[i-1]: ind += 1

        gr[ind].append(i)

    possible = True

    for x in range(w):

        for ind in range(ln+1):

            cnt = 0

            for y in gr[ind]:

                if s[y][x] == '1':

                    cnt += 1

            if cnt > k:

                possible = False

                break

        if not possible:

            break

    else:

        cutcnt = 0

        now = [0] * (ln+1)

        for x in range(w):

            for ind in range(ln+1):

                for y in gr[ind]:

                    if s[y][x] == '1':

                        now[ind] += 1

            if max(now) > k:

                now = [0] * (ln+1)

                cutcnt += 1

                for ind in range(ln+1):

                    for y in gr[ind]:

                        if s[y][x] == '1':

                            now[ind] += 1

        res = min(res, cutcnt + ln)

print(res)
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions
from decimal import Decimal

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, m, K = inpl()
s = [eval(input()) for _ in range(n)]
res = INF
for pat in itertools.product([0, 1], repeat=n - 1):
    pat = list(pat) + [0]
    group = []
    tmp = []
    for i, j in enumerate(pat):
        tmp += [i]
        if j or i == n - 1:
            group += [tmp]
            tmp = []
    ln = len(group)
    white = [[0] * ln for _ in range(m)]
    ccc = set()
    cnt = pat.count(1)
    ok = True
    for i in range(m):
        for j, z in enumerate(group):
            for k in z:
                if s[k][i] == "1":
                    white[i][j] += 1
            if max(white[i]) > K:
                ok = False
                break
    if not ok:
        continue
    now = [0] * ln
    for i in range(m):
        ok = True
        for j in range(ln):
            if now[j] + white[i][j] > K:
                ok = False
                break
        if ok:
            for j in range(ln):
                now[j] += white[i][j]
        else:
            cnt += 1
            for j in range(ln):
                now[j] = white[i][j]
    res = min(res, cnt)
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


h, w, k = inpl()
s = [list(eval(input())) for _ in range(h)]
res = INF
for yoko in itertools.product([0, 1], repeat=(h - 1)):
    # 0:uncut 1:cut
    ln = sum(yoko)
    gr = [[] for _ in range(ln + 1)]
    gr[0].append(0)
    ind = 0
    for i in range(1, h):
        if yoko[i - 1]:
            ind += 1
        gr[ind].append(i)
    possible = True
    for x in range(w):
        for ind in range(ln + 1):
            cnt = 0
            for y in gr[ind]:
                if s[y][x] == "1":
                    cnt += 1
            if cnt > k:
                possible = False
                break
        if not possible:
            break
    else:
        cutcnt = 0
        now = [0] * (ln + 1)
        for x in range(w):
            for ind in range(ln + 1):
                for y in gr[ind]:
                    if s[y][x] == "1":
                        now[ind] += 1
            if max(now) > k:
                now = [0] * (ln + 1)
                cutcnt += 1
                for ind in range(ln + 1):
                    for y in gr[ind]:
                        if s[y][x] == "1":
                            now[ind] += 1
        res = min(res, cutcnt + ln)
print(res)

-from heapq import heappop, heappush, heapify -import sys, bisect, math, itertools, fractions -from decimal import Decimal +from heapq import heappop, heappush +from bisect import bisect_left, bisect_right +import sys, math, itertools, fractions, pprint -n, m, K = inpl() -s = [eval(input()) for _ in range(n)] +h, w, k = inpl() +s = [list(eval(input())) for _ in range(h)] -for pat in itertools.product([0, 1], repeat=n - 1): -    pat = list(pat) + [0] -    group = [] -    tmp = [] -    for i, j in enumerate(pat): -        tmp += [i] -        if j or i == n - 1: -            group += [tmp] -            tmp = [] -    ln = len(group) -    white = [[0] * ln for _ in range(m)] -    ccc = set() -    cnt = pat.count(1) -    ok = True -    for i in range(m): -        for j, z in enumerate(group): -            for k in z: -                if s[k][i] == "1": -                    white[i][j] += 1 -            if max(white[i]) > K: -                ok = False +for yoko in itertools.product([0, 1], repeat=(h - 1)): +    # 0:uncut 1:cut +    ln = sum(yoko) +    gr = [[] for _ in range(ln + 1)] +    gr[0].append(0) +    ind = 0 +    for i in range(1, h): +        if yoko[i - 1]: +            ind += 1 +        gr[ind].append(i) +    possible = True +    for x in range(w): +        for ind in range(ln + 1): +            cnt = 0 +            for y in gr[ind]: +                if s[y][x] == "1": +                    cnt += 1 +            if cnt > k: +                possible = False -    if not ok: -        continue -    now = [0] * ln -    for i in range(m): -        ok = True -        for j in range(ln): -            if now[j] + white[i][j] > K: -                ok = False -                break -        if ok: -            for j in range(ln): -                now[j] += white[i][j] -        else: -            cnt += 1 -            for j in range(ln): -                now[j] = white[i][j] -    res = min(res, cnt) +        if not possible: +            break +    else: +        cutcnt = 0 +        now = [0] * (ln + 1) +        for x in range(w): +            for ind in range(ln + 1): +                for y in gr[ind]: +                    if s[y][x] == "1": +                        now[ind] += 1 +            if max(now) > k: +                now = [0] * (ln + 1) +                cutcnt += 1 +                for ind in range(ln + 1): +                    for y in gr[ind]: +                        if s[y][x] == "1": +                            now[ind] += 1 +        res = min(res, cutcnt + ln)