from itertools import product

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

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



ans = float("inf")



for pattern in product([0, 1], repeat = H - 1):

    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]

    rows = []

    for i in range(len(div) - 1):

        row = []

        for j in range(W):

            tmp = 0

            for k in range(div[i], div[i + 1]):

                tmp += G[k][j]

            row.append(tmp)

        rows.append(row)

        

    flag = True

    for row in rows:

        if [r for r in row if r > K]:

            flag = False

            break

    if not flag:

        continue



    tmp_ans = 0

    cnt = [0] * len(rows)

    w = 0



    while w < W:

        for r in range(len(rows)):

            cnt[r] += rows[r][w]

        if [c for c in cnt if c > K]:

            cnt = [0] * len(rows)

            tmp_ans += 1

            w -= 1

        w += 1

    

    tmp_ans += pattern.count(1)

    ans = min(ans, tmp_ans)



print(ans)
import sys



#da[i][j]:(0,0)~(i,j)の長方形の和

def da_generate(h, w, a):

    da = [[0] * w for j in range(h)]

    da[0][0] = a[0][0]

    for i in range(1, w):

        da[0][i] = da[0][i - 1] + a[0][i]

    for i in range(1, h):

        cnt_w = 0

        for j in range(w):

            cnt_w += a[i][j]

            da[i][j] = da[i - 1][j] + cnt_w

    return da



#da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和

def da_calc(p, q, x, y):

    if p > x or q > y:

        return 0

    if p == 0 and q == 0:

        return da[x][y]

    if p == 0:

        return da[x][y] - da[x][q - 1]

    if q == 0:

        return da[x][y] - da[p - 1][y]

    return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1]



H, W, K = list(map(int, sys.stdin.readline().rstrip().split()))

grid = [list(map(int, list(sys.stdin.readline().rstrip()))) for _ in range(H)]

da = da_generate(H, W, grid)



ans = 10 ** 18

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

    res = 0

    s = [k for k, j in enumerate(list(range(H)), 1) if i >> j & 1] # s行は含まない

    res += len(s)

    s.append(H)

    y = 0

    for w in range(1, W + 1): # w行は含まない

        x = 0

        flag = False

        for s_i in s:

            if da_calc(x, y, s_i - 1, w - 1) > K:

                if y + 1 < w:

                    res += 1

                    y = w - 1

                else:

                    flag = True

                break

            x = s_i

        else:

            pass

        if flag:

            break

    else:

        ans = min(ans, res)



print(ans)
from itertools import product

H, W, K = list(map(int, input().split()))
G = [list(map(int, list(eval(input())))) for _ in range(H)]
ans = float("inf")
for pattern in product([0, 1], repeat=H - 1):
    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
    rows = []
    for i in range(len(div) - 1):
        row = []
        for j in range(W):
            tmp = 0
            for k in range(div[i], div[i + 1]):
                tmp += G[k][j]
            row.append(tmp)
        rows.append(row)
    flag = True
    for row in rows:
        if [r for r in row if r > K]:
            flag = False
            break
    if not flag:
        continue
    tmp_ans = 0
    cnt = [0] * len(rows)
    w = 0
    while w < W:
        for r in range(len(rows)):
            cnt[r] += rows[r][w]
        if [c for c in cnt if c > K]:
            cnt = [0] * len(rows)
            tmp_ans += 1
            w -= 1
        w += 1
    tmp_ans += pattern.count(1)
    ans = min(ans, tmp_ans)
print(ans)

import sys

# da[i][j]:(0,0)~(i,j)の長方形の和
def da_generate(h, w, a):
    da = [[0] * w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i - 1] + a[0][i]
    for i in range(1, h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i - 1][j] + cnt_w
    return da


# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(p, q, x, y):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y] - da[x][q - 1]
    if q == 0:
        return da[x][y] - da[p - 1][y]
    return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1]


H, W, K = list(map(int, sys.stdin.readline().rstrip().split()))
grid = [list(map(int, list(sys.stdin.readline().rstrip()))) for _ in range(H)]
da = da_generate(H, W, grid)
ans = 10**18
for i in range(2 ** (H - 1)):
    res = 0
    s = [k for k, j in enumerate(list(range(H)), 1) if i >> j & 1]  # s行は含まない
    res += len(s)
    s.append(H)
    y = 0
    for w in range(1, W + 1):  # w行は含まない
        x = 0
        flag = False
        for s_i in s:
            if da_calc(x, y, s_i - 1, w - 1) > K:
                if y + 1 < w:
                    res += 1
                    y = w - 1
                else:
                    flag = True
                break
            x = s_i
        else:
            pass
        if flag:
            break
    else:
        ans = min(ans, res)
print(ans)

-from itertools import product +import sys -H, W, K = list(map(int, input().split())) -G = [list(map(int, list(eval(input())))) for _ in range(H)] -ans = float("inf") -for pattern in product([0, 1], repeat=H - 1): -    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H] -    rows = [] -    for i in range(len(div) - 1): -        row = [] -        for j in range(W): -            tmp = 0 -            for k in range(div[i], div[i + 1]): -                tmp += G[k][j] -            row.append(tmp) -        rows.append(row) -    flag = True -    for row in rows: -        if [r for r in row if r > K]: -            flag = False +# da[i][j]:(0,0)~(i,j)の長方形の和 +def da_generate(h, w, a): +    da = [[0] * w for j in range(h)] +    da[0][0] = a[0][0] +    for i in range(1, w): +        da[0][i] = da[0][i - 1] + a[0][i] +    for i in range(1, h): +        cnt_w = 0 +        for j in range(w): +            cnt_w += a[i][j] +            da[i][j] = da[i - 1][j] + cnt_w +    return da + + +# da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和 +def da_calc(p, q, x, y): +    if p > x or q > y: +        return 0 +    if p == 0 and q == 0: +        return da[x][y] +    if p == 0: +        return da[x][y] - da[x][q - 1] +    if q == 0: +        return da[x][y] - da[p - 1][y] +    return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1] + + +H, W, K = list(map(int, sys.stdin.readline().rstrip().split())) +grid = [list(map(int, list(sys.stdin.readline().rstrip()))) for _ in range(H)] +da = da_generate(H, W, grid) +ans = 10**18 +for i in range(2 ** (H - 1)): +    res = 0 +    s = [k for k, j in enumerate(list(range(H)), 1) if i >> j & 1]  # s行は含まない +    res += len(s) +    s.append(H) +    y = 0 +    for w in range(1, W + 1):  # w行は含まない +        x = 0 +        flag = False +        for s_i in s: +            if da_calc(x, y, s_i - 1, w - 1) > K: +                if y + 1 < w: +                    res += 1 +                    y = w - 1 +                else: +                    flag = True +                break +            x = s_i +        else: +            pass +        if flag: -    if not flag: -        continue -    tmp_ans = 0 -    cnt = [0] * len(rows) -    w = 0 -    while w < W: -        for r in range(len(rows)): -            cnt[r] += rows[r][w] -        if [c for c in cnt if c > K]: -            cnt = [0] * len(rows) -            tmp_ans += 1 -            w -= 1 -        w += 1 -    tmp_ans += pattern.count(1) -    ans = min(ans, tmp_ans) +    else: +        ans = min(ans, res)