#coding:utf-8

import sys,os

from collections import defaultdict, deque

from fractions import gcd

from math import ceil, floor

sys.setrecursionlimit(10**6)

write = sys.stdout.write

dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0

def main(given=sys.stdin.readline):

    input = lambda: given().rstrip()

    LMIIS = lambda: list(map(int,input().split()))

    II = lambda: int(input())

    XLMIIS = lambda x: [LMIIS() for _ in range(x)]

    YN = lambda c : print('Yes') if c else print('No')

    MOD = 10**9+7

    H,W,K = LMIIS()

    from itertools import accumulate

    S = [list(accumulate(map(int,input()))) for _ in range(H)]

    





    def divide(pattern):

        lenP = len(pattern)

        divided = [0]*lenP

        count = lenP - 1

        for i in range(lenP):

            if K < pattern[i][0]:

                return H+W

        for i in range(1,W):

            # print('divided=',divided)

            for j in range(lenP):

                if K < pattern[j][i] - divided[j]:

                    for l in range(lenP):

                        divided[l] = pattern[l][i-1]

                    count += 1

                    break

        # print('count=',count)

        return count

                    



            

        







    ans = H+W



    for i in range(2**H):

        pattern = []

        line = [0] * W

        for j in range(H):

            for k in range(W):

                line[k] += S[j][k]

            if 2**j & i:

                pattern.append(line)

                line = [0] * W

        pattern.append(line)

        # print(pattern)

        ans = min(divide(pattern),ans)

    print(ans)

    return

        

    



                



                

                



    



    



if __name__ == '__main__':

    main()

H,W,K = list(map(int,input().split()))

from itertools import accumulate

S = [list(accumulate(list(map(int,eval(input()))))) for _ in range(H)]



def divide(pattern):

    lenP = len(pattern)

    divided = [0]*lenP

    count = lenP - 1

    for i in range(lenP):

        if K < pattern[i][0]:

            return H+W

    for i in range(1,W):

        for j in range(lenP):

            if K < pattern[j][i] - divided[j]:

                for l in range(lenP):

                    divided[l] = pattern[l][i-1]

                count += 1

                break

    return count



ans = H+W

for i in range(2**H):

    pattern = []

    line = [0] * W

    for j in range(H):

        for k in range(W):

            line[k] += S[j][k]

        if 2**j & i:

            pattern.append(line)

            line = [0] * W

    pattern.append(line)

    ans = min(divide(pattern),ans)

print(ans)



# coding:utf-8
import sys, os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor

sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (
    (lambda *something: print(*something))
    if "TERM_PROGRAM" in os.environ
    else lambda *x: 0
)


def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int, input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c: print("Yes") if c else print("No")
    MOD = 10**9 + 7
    H, W, K = LMIIS()
    from itertools import accumulate

    S = [list(accumulate(map(int, input()))) for _ in range(H)]

    def divide(pattern):
        lenP = len(pattern)
        divided = [0] * lenP
        count = lenP - 1
        for i in range(lenP):
            if K < pattern[i][0]:
                return H + W
        for i in range(1, W):
            # print('divided=',divided)
            for j in range(lenP):
                if K < pattern[j][i] - divided[j]:
                    for l in range(lenP):
                        divided[l] = pattern[l][i - 1]
                    count += 1
                    break
        # print('count=',count)
        return count

    ans = H + W
    for i in range(2**H):
        pattern = []
        line = [0] * W
        for j in range(H):
            for k in range(W):
                line[k] += S[j][k]
            if 2**j & i:
                pattern.append(line)
                line = [0] * W
        pattern.append(line)
        # print(pattern)
        ans = min(divide(pattern), ans)
    print(ans)
    return


if __name__ == "__main__":
    main()

H, W, K = list(map(int, input().split()))
from itertools import accumulate

S = [list(accumulate(list(map(int, eval(input()))))) for _ in range(H)]


def divide(pattern):
    lenP = len(pattern)
    divided = [0] * lenP
    count = lenP - 1
    for i in range(lenP):
        if K < pattern[i][0]:
            return H + W
    for i in range(1, W):
        for j in range(lenP):
            if K < pattern[j][i] - divided[j]:
                for l in range(lenP):
                    divided[l] = pattern[l][i - 1]
                count += 1
                break
    return count


ans = H + W
for i in range(2**H):
    pattern = []
    line = [0] * W
    for j in range(H):
        for k in range(W):
            line[k] += S[j][k]
        if 2**j & i:
            pattern.append(line)
            line = [0] * W
    pattern.append(line)
    ans = min(divide(pattern), ans)
print(ans)

-# coding:utf-8 -import sys, os -from collections import defaultdict, deque -from fractions import gcd -from math import ceil, floor +H, W, K = list(map(int, input().split())) +from itertools import accumulate -sys.setrecursionlimit(10**6) -write = sys.stdout.write -dbg = ( -    (lambda *something: print(*something)) -    if "TERM_PROGRAM" in os.environ -    else lambda *x: 0 -) +S = [list(accumulate(list(map(int, eval(input()))))) for _ in range(H)] -def main(given=sys.stdin.readline): -    input = lambda: given().rstrip() -    LMIIS = lambda: list(map(int, input().split())) -    II = lambda: int(input()) -    XLMIIS = lambda x: [LMIIS() for _ in range(x)] -    YN = lambda c: print("Yes") if c else print("No") -    MOD = 10**9 + 7 -    H, W, K = LMIIS() -    from itertools import accumulate - -    S = [list(accumulate(map(int, input()))) for _ in range(H)] - -    def divide(pattern): -        lenP = len(pattern) -        divided = [0] * lenP -        count = lenP - 1 -        for i in range(lenP): -            if K < pattern[i][0]: -                return H + W -        for i in range(1, W): -            # print('divided=',divided) -            for j in range(lenP): -                if K < pattern[j][i] - divided[j]: -                    for l in range(lenP): -                        divided[l] = pattern[l][i - 1] -                    count += 1 -                    break -        # print('count=',count) -        return count - -    ans = H + W -    for i in range(2**H): -        pattern = [] -        line = [0] * W -        for j in range(H): -            for k in range(W): -                line[k] += S[j][k] -            if 2**j & i: -                pattern.append(line) -                line = [0] * W -        pattern.append(line) -        # print(pattern) -        ans = min(divide(pattern), ans) -    print(ans) -    return +def divide(pattern): +    lenP = len(pattern) +    divided = [0] * lenP +    count = lenP - 1 +    for i in range(lenP): +        if K < pattern[i][0]: +            return H + W +    for i in range(1, W): +        for j in range(lenP): +            if K < pattern[j][i] - divided[j]: +                for l in range(lenP): +                    divided[l] = pattern[l][i - 1] +                count += 1 +                break +    return count -if __name__ == "__main__": -    main() +ans = H + W +for i in range(2**H): +    pattern = [] +    line = [0] * W +    for j in range(H): +        for k in range(W): +            line[k] += S[j][k] +        if 2**j & i: +            pattern.append(line) +            line = [0] * W +    pattern.append(line) +    ans = min(divide(pattern), ans) +print(ans)