def main():

    h, w, k = list(map(int, input().split()))

    s = [[int(i) for i in list(eval(input()))] for _ in range(h)]

    cnt = [bin(i).count("1") for i in range(2**(h - 1))]

    c = 0

    for ci in [sum(i) for i in zip(*s)]:

        if ci > k:

            cnt[0] = 100000

            break

        c += ci

        if c > k:

            cnt[0] += 1

            c = ci

    for i in range(1, 2**(h - 1)):

        div = [j + 1 for j in range(h) if i & 2**j]

        ss = []

        l = 0

        for d in div:

            ss.append(s[l:d])

            l = d

        ss.append(s[l:])

        c = [0] * len(ss)

        t = [[sum(i) for i in zip(*si)] for si in ss]

        for j in range(w):

            if max(ti[j] for ti in t) > k:

                cnt[i] = 100000

                break

            for tt, ti in enumerate(t):

                c[tt] += ti[j]

            if max(c) > k:

                cnt[i] += 1

                c = [ti[j] for ti in t]

    print((min(cnt)))



if __name__ == '__main__':

    main()
def main():

    h, w, k = list(map(int, input().split()))

    s = [[int(i) for i in list(eval(input()))] for _ in range(h)]

    cnt = [bin(i).count("1") for i in range(2**(h - 1))]

    c = 0

    for ci in [sum(i) for i in zip(*s)]:

        if ci > k:

            cnt[0] = 100000

            break

        c += ci

        if c > k:

            cnt[0] += 1

            c = ci

    minc = cnt[0]

    for i in range(1, 2**(h - 1)):

        div = [j + 1 for j in range(h) if i & 2**j]

        ss = []

        l = 0

        for d in div:

            ss.append(s[l:d])

            l = d

        ss.append(s[l:])

        c = [0] * len(ss)

        t = [[sum(i) for i in zip(*si)] for si in ss]

        for j in range(w):

            if cnt[i] >= minc:

                break

            if max(ti[j] for ti in t) > k:

                cnt[i] = 100000

                break

            for tt, ti in enumerate(t):

                c[tt] += ti[j]

            if max(c) > k:

                cnt[i] += 1

                c = [ti[j] for ti in t]

    print((min(cnt)))



if __name__ == '__main__':

    main()
def main():
    h, w, k = list(map(int, input().split()))
    s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2 ** (h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    for i in range(1, 2 ** (h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print((min(cnt)))


if __name__ == "__main__":
    main()

def main():
    h, w, k = list(map(int, input().split()))
    s = [[int(i) for i in list(eval(input()))] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2 ** (h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    minc = cnt[0]
    for i in range(1, 2 ** (h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if cnt[i] >= minc:
                break
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print((min(cnt)))


if __name__ == "__main__":
    main()

+    minc = cnt[0] +            if cnt[i] >= minc: +                break