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

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



ans = 10 ** 5

for bit in range(2 ** (H - 1)):    

    group = [0] * H

    gnum = 0



    # Group each row

    for i in range(H - 1):

        if not bit >> i & 1:

            group[i + 1] = group[i]

        else:

            group[i + 1] = group[i] + 1

            gnum += 1



    gok = True

    add = 0  # Vertical split num

    nums = [0] * (gnum + 1)  # Number of '1' in previous blocks

    # For each column

    for j in range(W):

        ones = [0] * (gnum + 1)

        ok = True

        # For each row

        for i in range(H):

            ones[group[i]] += int(S[i][j])

            nums[group[i]] += int(S[i][j])

            if ones[group[i]] > K: gok = False;

            if nums[group[i]] > K: ok = False;



        if not ok:

            add += 1

            nums = ones[:]

            

    if gok:

        ans = min(ans, gnum + add)

                

    

print(ans)



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

X = [list(eval(input())) for _ in range(H)]

MOD = 10 ** 9 + 7

ans = MOD



for bit in range(2 ** (H - 1)):

    n = bin(bit).count("1")

    ctr = [0] * (n + 1)  # Accumulation

    res = 0

    for j in range(W):

        k = 0

        tmp = [0] * (n + 1)  # One column

        for i in range(H):

            tmp[k] += int(X[i][j])

            if bit >> i & 1:

                k += 1



        # Check counts

        if any(v > K for v in tmp):

            res = MOD

            break

        elif any(u + v > K for u, v in zip(ctr, tmp)):

            # Split

            res += 1

            ctr = tmp[:]

        else:

            # Accumulate

            for i in range(n + 1):

                ctr[i] += tmp[i]



    ans = min(ans, res + n)



print(ans)

H, W, K = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
ans = 10**5
for bit in range(2 ** (H - 1)):
    group = [0] * H
    gnum = 0
    # Group each row
    for i in range(H - 1):
        if not bit >> i & 1:
            group[i + 1] = group[i]
        else:
            group[i + 1] = group[i] + 1
            gnum += 1
    gok = True
    add = 0  # Vertical split num
    nums = [0] * (gnum + 1)  # Number of '1' in previous blocks
    # For each column
    for j in range(W):
        ones = [0] * (gnum + 1)
        ok = True
        # For each row
        for i in range(H):
            ones[group[i]] += int(S[i][j])
            nums[group[i]] += int(S[i][j])
            if ones[group[i]] > K:
                gok = False
            if nums[group[i]] > K:
                ok = False
        if not ok:
            add += 1
            nums = ones[:]
    if gok:
        ans = min(ans, gnum + add)
print(ans)

H, W, K = list(map(int, input().split()))
X = [list(eval(input())) for _ in range(H)]
MOD = 10**9 + 7
ans = MOD
for bit in range(2 ** (H - 1)):
    n = bin(bit).count("1")
    ctr = [0] * (n + 1)  # Accumulation
    res = 0
    for j in range(W):
        k = 0
        tmp = [0] * (n + 1)  # One column
        for i in range(H):
            tmp[k] += int(X[i][j])
            if bit >> i & 1:
                k += 1
        # Check counts
        if any(v > K for v in tmp):
            res = MOD
            break
        elif any(u + v > K for u, v in zip(ctr, tmp)):
            # Split
            res += 1
            ctr = tmp[:]
        else:
            # Accumulate
            for i in range(n + 1):
                ctr[i] += tmp[i]
    ans = min(ans, res + n)
print(ans)

-S = [eval(input()) for _ in range(H)] -ans = 10**5 +X = [list(eval(input())) for _ in range(H)] +MOD = 10**9 + 7 +ans = MOD -    group = [0] * H -    gnum = 0 -    # Group each row -    for i in range(H - 1): -        if not bit >> i & 1: -            group[i + 1] = group[i] +    n = bin(bit).count("1") +    ctr = [0] * (n + 1)  # Accumulation +    res = 0 +    for j in range(W): +        k = 0 +        tmp = [0] * (n + 1)  # One column +        for i in range(H): +            tmp[k] += int(X[i][j]) +            if bit >> i & 1: +                k += 1 +        # Check counts +        if any(v > K for v in tmp): +            res = MOD +            break +        elif any(u + v > K for u, v in zip(ctr, tmp)): +            # Split +            res += 1 +            ctr = tmp[:] -            group[i + 1] = group[i] + 1 -            gnum += 1 -    gok = True -    add = 0  # Vertical split num -    nums = [0] * (gnum + 1)  # Number of '1' in previous blocks -    # For each column -    for j in range(W): -        ones = [0] * (gnum + 1) -        ok = True -        # For each row -        for i in range(H): -            ones[group[i]] += int(S[i][j]) -            nums[group[i]] += int(S[i][j]) -            if ones[group[i]] > K: -                gok = False -            if nums[group[i]] > K: -                ok = False -        if not ok: -            add += 1 -            nums = ones[:] -    if gok: -        ans = min(ans, gnum + add) +            # Accumulate +            for i in range(n + 1): +                ctr[i] += tmp[i] +    ans = min(ans, res + n)