import sys

from itertools import combinations as combi

input = sys.stdin.readline

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

S = [list(eval(input()))[: -1] for _ in range(H)]

cs = [[0] * (W + 1) for _ in range(H)]

for i in range(H):

  for j in range(W): cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")

res = H * W

#print(cs)

for t in range(H):

  for c in combi([x for x in range(H - 1)], t):

    l = 0

    tres = 0

    while l < W:

      ok = l

      ng = W + 1

      while ng - ok > 1:

        m = (ok + ng) // 2

        tt = 0

        i = 0

        ttt = 0

        while i < H:

          ttt += cs[i][m] - cs[i][l]

          if i in c:

            tt = max(tt, ttt)

            ttt = 0

          i += 1

        tt = max(tt, ttt)

        if tt <= K: ok = m

        else: ng = m

      if l == ok:

        tres = H * W

        break

      l = ok

      tres += int(l < W)



    #print(c, tres)

    res = min(res, tres + len(c))

print(res)
import sys

from itertools import combinations as combi

input = sys.stdin.readline

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

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

res = H + W - 2

for t in range(H):

  for c in combi([x for x in range(1, H)], t):

    s = set(c)

    table = [0] * (t + 1)

    rres = t + 0

    for x in range(W):

      i = 0

      y = 0

      while y < H:

        if y in s: i += 1

        table[i] += S[y][x]

        y += 1

        if table[i] > K: break

      else: continue

      rres += 1

      table = [0] * (t + 1)

      i = 0

      y = 0

      while y < H:

        if y in s: i += 1

        table[i] += S[y][x]

        y += 1

        if table[i] > K: break

      else: continue

      rres = H + W - 2

      break



    #print(c, rres, table)

    res = min(res, rres)

print(res)
import sys
from itertools import combinations as combi

input = sys.stdin.readline
H, W, K = list(map(int, input().split()))
S = [list(eval(input()))[:-1] for _ in range(H)]
cs = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
    for j in range(W):
        cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1")
res = H * W
# print(cs)
for t in range(H):
    for c in combi([x for x in range(H - 1)], t):
        l = 0
        tres = 0
        while l < W:
            ok = l
            ng = W + 1
            while ng - ok > 1:
                m = (ok + ng) // 2
                tt = 0
                i = 0
                ttt = 0
                while i < H:
                    ttt += cs[i][m] - cs[i][l]
                    if i in c:
                        tt = max(tt, ttt)
                        ttt = 0
                    i += 1
                tt = max(tt, ttt)
                if tt <= K:
                    ok = m
                else:
                    ng = m
            if l == ok:
                tres = H * W
                break
            l = ok
            tres += int(l < W)
        # print(c, tres)
        res = min(res, tres + len(c))
print(res)

import sys
from itertools import combinations as combi

input = sys.stdin.readline
H, W, K = list(map(int, input().split()))
S = [list(map(int, list(eval(input()))[:-1])) for _ in range(H)]
res = H + W - 2
for t in range(H):
    for c in combi([x for x in range(1, H)], t):
        s = set(c)
        table = [0] * (t + 1)
        rres = t + 0
        for x in range(W):
            i = 0
            y = 0
            while y < H:
                if y in s:
                    i += 1
                table[i] += S[y][x]
                y += 1
                if table[i] > K:
                    break
            else:
                continue
            rres += 1
            table = [0] * (t + 1)
            i = 0
            y = 0
            while y < H:
                if y in s:
                    i += 1
                table[i] += S[y][x]
                y += 1
                if table[i] > K:
                    break
            else:
                continue
            rres = H + W - 2
            break
        # print(c, rres, table)
        res = min(res, rres)
print(res)

-S = [list(eval(input()))[:-1] for _ in range(H)] -cs = [[0] * (W + 1) for _ in range(H)] -for i in range(H): -    for j in range(W): -        cs[i][j + 1] = cs[i][j] + int(S[i][j] == "1") -res = H * W -# print(cs) +S = [list(map(int, list(eval(input()))[:-1])) for _ in range(H)] +res = H + W - 2 -    for c in combi([x for x in range(H - 1)], t): -        l = 0 -        tres = 0 -        while l < W: -            ok = l -            ng = W + 1 -            while ng - ok > 1: -                m = (ok + ng) // 2 -                tt = 0 -                i = 0 -                ttt = 0 -                while i < H: -                    ttt += cs[i][m] - cs[i][l] -                    if i in c: -                        tt = max(tt, ttt) -                        ttt = 0 +    for c in combi([x for x in range(1, H)], t): +        s = set(c) +        table = [0] * (t + 1) +        rres = t + 0 +        for x in range(W): +            i = 0 +            y = 0 +            while y < H: +                if y in s: -                tt = max(tt, ttt) -                if tt <= K: -                    ok = m -                else: -                    ng = m -            if l == ok: -                tres = H * W -                break -            l = ok -            tres += int(l < W) -        # print(c, tres) -        res = min(res, tres + len(c)) +                table[i] += S[y][x] +                y += 1 +                if table[i] > K: +                    break +            else: +                continue +            rres += 1 +            table = [0] * (t + 1) +            i = 0 +            y = 0 +            while y < H: +                if y in s: +                    i += 1 +                table[i] += S[y][x] +                y += 1 +                if table[i] > K: +                    break +            else: +                continue +            rres = H + W - 2 +            break +        # print(c, rres, table) +        res = min(res, rres)