#na-

import itertools

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

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

def check(k):

    if k <= K:

        return(True)

    else:

        return(False)

        

noans = 0

def make_lst(i):

    global noans, lst, havelst

    temp = S[0][i]

    for h in range(H-1):

        if y[h]:

            lst.append(temp)

            temp = S[h+1][i]

        else:

            temp += S[h+1][i]

    lst.append(temp)

    if check(max(lst)):

        havelst = 1

    else:

        noans = 1

               

def nocut(i):

    global cutnum, lst, havelst

    prelst = []

    temp = S[0][i]

    j = 0

    for h in range(H-1):

        if y[h]:

            lst[j] += temp

            prelst.append(temp)

            j += 1

            temp = S[h+1][i]

        else:

            temp += S[h+1][i]

    prelst.append(temp)

    lst[-1] += temp

    if check(max(lst)):

        return(True)

    else:

        cutnum += 1

        lst = prelst        

                 

ans = float("inf")

cutlst = []    

for y in itertools.product((0, 1), repeat=H-1):

    havelst = 0

    lst = []

    cutnum = sum(y)

    for x in range(W):

        if noans:

            break

        if havelst:

            nocut(x)

        else:

            make_lst(x)

    if noans==1:

        noans = 0

        continue

    ans = min(cutnum, ans)

print(ans)
def add(in1, in2):

    return [a + b for a, b in zip(in1, in2)]

 

def split(ar, k, w):

    a = 0

    if max(max(ar)) > k:

      return -1

    tm = ar[0]

    for i in range(1, w):

        tm = add(tm, ar[i])

        if max(tm) > k:

            a += 1

            tm = ar[i]

    return a        

 

h, w, k = list(map(int, input().split()))

s = [[int(i) for i in eval(input())] for j in range(h)]

ans = h*w

 

for i in range(2**(h-1)):

    data = []

    temp = s[0]

    sp = bin(i+2**h)[4:]

    if ans < sp.count("1"):

        continue

    for j in range(1, h):

        if sp[j-1] == "0":

            temp = add(temp, s[j])

        else:

            data.append(temp)

            temp = s[j]

    data.append(temp)

    ans_ = split([list(x) for x in zip(*data)], k, w)

    if ans_ == -1:

        continue

    ans_ += sp.count("1")

    if ans > ans_:

        ans = ans_

print(ans)

# na-
import itertools

H, W, K = list(map(int, input().split()))
S = [list(map(int, list(eval(input())))) for _ in range(H)]


def check(k):
    if k <= K:
        return True
    else:
        return False


noans = 0


def make_lst(i):
    global noans, lst, havelst
    temp = S[0][i]
    for h in range(H - 1):
        if y[h]:
            lst.append(temp)
            temp = S[h + 1][i]
        else:
            temp += S[h + 1][i]
    lst.append(temp)
    if check(max(lst)):
        havelst = 1
    else:
        noans = 1


def nocut(i):
    global cutnum, lst, havelst
    prelst = []
    temp = S[0][i]
    j = 0
    for h in range(H - 1):
        if y[h]:
            lst[j] += temp
            prelst.append(temp)
            j += 1
            temp = S[h + 1][i]
        else:
            temp += S[h + 1][i]
    prelst.append(temp)
    lst[-1] += temp
    if check(max(lst)):
        return True
    else:
        cutnum += 1
        lst = prelst


ans = float("inf")
cutlst = []
for y in itertools.product((0, 1), repeat=H - 1):
    havelst = 0
    lst = []
    cutnum = sum(y)
    for x in range(W):
        if noans:
            break
        if havelst:
            nocut(x)
        else:
            make_lst(x)
    if noans == 1:
        noans = 0
        continue
    ans = min(cutnum, ans)
print(ans)

def add(in1, in2):
    return [a + b for a, b in zip(in1, in2)]


def split(ar, k, w):
    a = 0
    if max(max(ar)) > k:
        return -1
    tm = ar[0]
    for i in range(1, w):
        tm = add(tm, ar[i])
        if max(tm) > k:
            a += 1
            tm = ar[i]
    return a


h, w, k = list(map(int, input().split()))
s = [[int(i) for i in eval(input())] for j in range(h)]
ans = h * w
for i in range(2 ** (h - 1)):
    data = []
    temp = s[0]
    sp = bin(i + 2**h)[4:]
    if ans < sp.count("1"):
        continue
    for j in range(1, h):
        if sp[j - 1] == "0":
            temp = add(temp, s[j])
        else:
            data.append(temp)
            temp = s[j]
    data.append(temp)
    ans_ = split([list(x) for x in zip(*data)], k, w)
    if ans_ == -1:
        continue
    ans_ += sp.count("1")
    if ans > ans_:
        ans = ans_
print(ans)

-# na- -import itertools - -H, W, K = list(map(int, input().split())) -S = [list(map(int, list(eval(input())))) for _ in range(H)] +def add(in1, in2): +    return [a + b for a, b in zip(in1, in2)] -def check(k): -    if k <= K: -        return True -    else: -        return False +def split(ar, k, w): +    a = 0 +    if max(max(ar)) > k: +        return -1 +    tm = ar[0] +    for i in range(1, w): +        tm = add(tm, ar[i]) +        if max(tm) > k: +            a += 1 +            tm = ar[i] +    return a -noans = 0 - - -def make_lst(i): -    global noans, lst, havelst -    temp = S[0][i] -    for h in range(H - 1): -        if y[h]: -            lst.append(temp) -            temp = S[h + 1][i] +h, w, k = list(map(int, input().split())) +s = [[int(i) for i in eval(input())] for j in range(h)] +ans = h * w +for i in range(2 ** (h - 1)): +    data = [] +    temp = s[0] +    sp = bin(i + 2**h)[4:] +    if ans < sp.count("1"): +        continue +    for j in range(1, h): +        if sp[j - 1] == "0": +            temp = add(temp, s[j]) -            temp += S[h + 1][i] -    lst.append(temp) -    if check(max(lst)): -        havelst = 1 -    else: -        noans = 1 - - -def nocut(i): -    global cutnum, lst, havelst -    prelst = [] -    temp = S[0][i] -    j = 0 -    for h in range(H - 1): -        if y[h]: -            lst[j] += temp -            prelst.append(temp) -            j += 1 -            temp = S[h + 1][i] -        else: -            temp += S[h + 1][i] -    prelst.append(temp) -    lst[-1] += temp -    if check(max(lst)): -        return True -    else: -        cutnum += 1 -        lst = prelst - - -ans = float("inf") -cutlst = [] -for y in itertools.product((0, 1), repeat=H - 1): -    havelst = 0 -    lst = [] -    cutnum = sum(y) -    for x in range(W): -        if noans: -            break -        if havelst: -            nocut(x) -        else: -            make_lst(x) -    if noans == 1: -        noans = 0 +            data.append(temp) +            temp = s[j] +    data.append(temp) +    ans_ = split([list(x) for x in zip(*data)], k, w) +    if ans_ == -1: -    ans = min(cutnum, ans) +    ans_ += sp.count("1") +    if ans > ans_: +        ans = ans_