/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-22-20.33.12 Sunday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int h, w, k, team[50], val[50][1100];
char mat[50][1100];

int makeTeam(int x) {
    vi a;
    for (int i = 0; i <= h-2; ++i) {
        if (x&(1<<i)) {
            a.eb(i);
        }
    }
    int tot = 1;
    if (!SZ(a)) {
        forn(i, h) team[i] = 1;
    } else {
        int len = SZ(a);
        for (int i = 0; i <= a[0]; ++i) team[i] = tot;
        ++tot;
        for (int i = 0; i < len-1; ++i) {
            for (int j = a[i]+1; j <= a[i+1]; ++j) {
                team[j] = tot;
            }
            ++tot;
        }
        for (int i = a[len-1]+1; i < h; ++i) team[i] = tot;
    }
    return tot;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> h >> w >> k;
    for (int i = 0; i < h; ++i){
        for (int j = 0; j < w; ++j) {
            cin >> mat[i][j];
            val[i][j] = int(mat[i][j]-'0');
        }
    }
    int ans = h-1+w-1;
    for (int i = 0; i < (1<<(h-1)); ++i) {
        ms(team, -1);
        int cnt = makeTeam(i)-1;
        int now[50];
        ms(now, 0);
        bool impossible = false;
        int pref = 0;
        for (int j = 0; j < w; ++j) {
            for (int o = 0; o < h; ++o) {
                now[team[o]] += val[o][j];
                if (now[team[o]] > k) {
                    ms(now, 0);
                    ++cnt;
                    if (pref == j) impossible = true;
                    pref = j;
                    --j;
                    break;
                }
            }
            if (impossible) break;
        }
        if (!impossible) ans = min(ans, cnt);
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 384