#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXH = 10 + 2;
const i64 MAXW = 1'000 + 3;

i64 h, w, k;
string a[MAXH];

i64 S[MAXH][MAXW];

inline i64 sum(pair<i64, i64> top, pair<i64, i64> bot) {
    i64 R = 0;
    R += S[bot.first][bot.second];
    R -= S[top.first - 1][bot.second];
    R -= S[bot.first][top.second - 1];
    R += S[top.first - 1][top.second - 1];
    return R;
}

i64 solve(vector<pair<i64, i64>>& q) {
    i64 R = q.size() - 1;

    //vector<i64> e;
    //e.resize(q.size());

    //memset(e.data(), 0, e.size() * sizeof(e[0]));

    i64 l = 1;
    for (i64 r = 1; r <= w; r++) {
        bool f = false;
        for (auto c : q) {
            i64 t = sum({ c.first, l }, {c.second, r});
            if (t > k) {
                f = true;
            }
        }

        if (f) {
            if (l == r) {
                return inf;
            }
            l = r;
            R += 1;
        }
    }

    return R;
}

i64 solve(i64 msk) {
    vector<pair<i64, i64>> q;
    i64 l = 1;
    i64 r = 1;
    while (msk) {
        if (msk & 1) {
            q.push_back({ l, r });
        }
        r += 1;
        if (msk & 1) {
            l = r;
        }
        msk >>= 1;
    }
    q.push_back({ l, h });
    /*
    cerr << "----------" << endl;
    for (auto t : q) {
        cerr << t.first << "-" << t.second << endl;
    }
    */

    i64 R = solve(q);
    return R;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> h >> w >> k;

    //for (i64 i = 1; i <= h; i++) {
    //    a[i].resize(w + 2);
    //    for (i64 j = 1; j <= w; j++) {
    //        a[i][j] = '1';
    //    }
    //}

    for (i64 i = 1; i <= h; i++) {
        cin >> a[i];
        a[i] = " " + a[i];
    }

    for (i64 i = 1; i <= h; i++) {
        for (i64 j = 1; j <= w; j++) {
            S[i][j] = S[i][j - 1] + a[i][j] - '0';
        }
        for (i64 j = 1; j <= w; j++) {
            S[i][j] = S[i - 1][j] + S[i][j];
        }

    }

    /*
    cerr << sum({1, 1}, {h, w}) << endl;
    cerr << sum({ 2, 2 }, { 3, 3 }) << endl;
    cerr << sum({ 2, 2 }, { 3, 4 }) << endl;
    cerr << sum({ 2, 2 }, { 3, 5 }) << endl;
    cerr << sum({ 2, 2 }, { 3, 6 }) << endl;
    */

    /*
    vector<pair<i64, i64>> te = { {1, 2}, {3, 4} };
    i64 tr = solve(te);
    cerr << tr << endl;
    */

    i64 R = inf;
    for (i64 i = 0; i < (1ll << (h - 1)); i++) {
        R = min(R, solve(i));
    }
    cout << R << endl;

    return 0;
}

Measured memory_bytes: 384