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

S = [eval(input()) for i in range(H)]



ans = H+W

for b in range(1<<(H-1)):

    tmp = bin(b).count('1')

    ks = [0]*H

    valid = True

    for col in zip(*S):

        j = 0

        for i,c in enumerate(col):

            if c=='1':

                ks[j] += 1

            if b&(1<<i):

                j = i+1

        if any(k > K for k in ks):

            tmp += 1

            ks = [0]*H

            j = 0

            for i,c in enumerate(col):

                if c=='1':

                    ks[j] += 1

                if b&(1<<i):

                    j = i+1

            if any(k > K for k in ks):

                valid = False

                break

    if valid:

        ans = min(ans,tmp)

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

S = [eval(input()) for i in range(H)]



ans = H+W

for b in range(1<<(H-1)):

    gs = [[0]]

    for k in range(H-1):

        if b&(1<<k):

            gs.append([k+1])

        else:

            gs[-1].append(k+1)

    tmp = bin(b).count('1')

    ws = [0] * len(gs)

    for x in range(W):

        for i,g in enumerate(gs):

            for h in g:

                if S[h][x] == '1':

                    ws[i] += 1

        if any(w>K for w in ws):

            tmp += 1

            ws = [0] * len(gs)

            for i,g in enumerate(gs):

                for h in g:

                    if S[h][x] == '1':

                        ws[i] += 1

            if any(w>K for w in ws):

                tmp = H+W

                break

    ans = min(ans,tmp)

print(ans)
H, W, K = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
ans = H + W
for b in range(1 << (H - 1)):
    tmp = bin(b).count("1")
    ks = [0] * H
    valid = True
    for col in zip(*S):
        j = 0
        for i, c in enumerate(col):
            if c == "1":
                ks[j] += 1
            if b & (1 << i):
                j = i + 1
        if any(k > K for k in ks):
            tmp += 1
            ks = [0] * H
            j = 0
            for i, c in enumerate(col):
                if c == "1":
                    ks[j] += 1
                if b & (1 << i):
                    j = i + 1
            if any(k > K for k in ks):
                valid = False
                break
    if valid:
        ans = min(ans, tmp)
print(ans)

H, W, K = list(map(int, input().split()))
S = [eval(input()) for i in range(H)]
ans = H + W
for b in range(1 << (H - 1)):
    gs = [[0]]
    for k in range(H - 1):
        if b & (1 << k):
            gs.append([k + 1])
        else:
            gs[-1].append(k + 1)
    tmp = bin(b).count("1")
    ws = [0] * len(gs)
    for x in range(W):
        for i, g in enumerate(gs):
            for h in g:
                if S[h][x] == "1":
                    ws[i] += 1
        if any(w > K for w in ws):
            tmp += 1
            ws = [0] * len(gs)
            for i, g in enumerate(gs):
                for h in g:
                    if S[h][x] == "1":
                        ws[i] += 1
            if any(w > K for w in ws):
                tmp = H + W
                break
    ans = min(ans, tmp)
print(ans)

+    gs = [[0]] +    for k in range(H - 1): +        if b & (1 << k): +            gs.append([k + 1]) +        else: +            gs[-1].append(k + 1) -    ks = [0] * H -    valid = True -    for col in zip(*S): -        j = 0 -        for i, c in enumerate(col): -            if c == "1": -                ks[j] += 1 -            if b & (1 << i): -                j = i + 1 -        if any(k > K for k in ks): +    ws = [0] * len(gs) +    for x in range(W): +        for i, g in enumerate(gs): +            for h in g: +                if S[h][x] == "1": +                    ws[i] += 1 +        if any(w > K for w in ws): -            ks = [0] * H -            j = 0 -            for i, c in enumerate(col): -                if c == "1": -                    ks[j] += 1 -                if b & (1 << i): -                    j = i + 1 -            if any(k > K for k in ks): -                valid = False +            ws = [0] * len(gs) +            for i, g in enumerate(gs): +                for h in g: +                    if S[h][x] == "1": +                        ws[i] += 1 +            if any(w > K for w in ws): +                tmp = H + W -    if valid: -        ans = min(ans, tmp) +    ans = min(ans, tmp)