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

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



# 横の割り方を全通り試す(2**(H-1))

ans = float('inf')

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

    _ans = bin(i).count('1')

    chocos = [list(map(int, S[0]))]

    for j in range(H-1):

        if i >> j & 1:

            chocos.append(list(map(int, S[j+1])))

        else:

            for w in range(W):

                chocos[-1][w] += int(S[j+1][w])

    

    ns = len(chocos)

    nums = [0] * ns

    is_next = False

    for w in range(W):

        for j in range(ns):

            nums[j] += chocos[j][w]

            if chocos[j][w] > K:

                _ans = float('inf')

            if nums[j] > K:

                _ans += 1

                is_next = True

                break

        

        if is_next:

            for j in range(ns):

                nums[j] = chocos[j][w]

            is_next = False

    

    ans = min(ans, _ans)



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

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



# 横の割り方を全通り試す(2**(H-1))

ans = float('inf')

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

    _ans = bin(i).count('1')

    chocos = [list(map(int, S[0]))]

    for j in range(H-1):

        if i >> j & 1:

            chocos.append(list(map(int, S[j+1])))

        else:

            for w in range(W):

                chocos[-1][w] += int(S[j+1][w])

    

    ns = len(chocos)

    nums = [0] * ns

    is_next = False

    flag = False

    for w in range(W):

        for j in range(ns):

            nums[j] += chocos[j][w]

            if chocos[j][w] > K:

                _ans = float('inf')

                flag = True

                break

            if nums[j] > K:

                _ans += 1

                is_next = True

                break

        if flag:

          flag = False

          break        

        if is_next:

            for j in range(ns):

                nums[j] = chocos[j][w]

            is_next = False

    

    ans = min(ans, _ans)



print(ans)
H, W, K = list(map(int, input().split()))
S = [eval(input()) for h in range(H)]
# 横の割り方を全通り試す(2**(H-1))
ans = float("inf")
for i in range(2 ** (H - 1)):
    _ans = bin(i).count("1")
    chocos = [list(map(int, S[0]))]
    for j in range(H - 1):
        if i >> j & 1:
            chocos.append(list(map(int, S[j + 1])))
        else:
            for w in range(W):
                chocos[-1][w] += int(S[j + 1][w])
    ns = len(chocos)
    nums = [0] * ns
    is_next = False
    for w in range(W):
        for j in range(ns):
            nums[j] += chocos[j][w]
            if chocos[j][w] > K:
                _ans = float("inf")
            if nums[j] > K:
                _ans += 1
                is_next = True
                break
        if is_next:
            for j in range(ns):
                nums[j] = chocos[j][w]
            is_next = False
    ans = min(ans, _ans)
print(ans)

H, W, K = list(map(int, input().split()))
S = [eval(input()) for h in range(H)]
# 横の割り方を全通り試す(2**(H-1))
ans = float("inf")
for i in range(2 ** (H - 1)):
    _ans = bin(i).count("1")
    chocos = [list(map(int, S[0]))]
    for j in range(H - 1):
        if i >> j & 1:
            chocos.append(list(map(int, S[j + 1])))
        else:
            for w in range(W):
                chocos[-1][w] += int(S[j + 1][w])
    ns = len(chocos)
    nums = [0] * ns
    is_next = False
    flag = False
    for w in range(W):
        for j in range(ns):
            nums[j] += chocos[j][w]
            if chocos[j][w] > K:
                _ans = float("inf")
                flag = True
                break
            if nums[j] > K:
                _ans += 1
                is_next = True
                break
        if flag:
            flag = False
            break
        if is_next:
            for j in range(ns):
                nums[j] = chocos[j][w]
            is_next = False
    ans = min(ans, _ans)
print(ans)

+    flag = False +                flag = True +                break +        if flag: +            flag = False +            break