#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int countbits(long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void solve() {
    int h,w,k;
    cin >> h >> w >> k;
    VS s(h);
    REP(i,0,h) cin >> s[i];
    VVI a(h,VI(w));
    REP(i,0,h) REP(j,0,w) a[i][j] = s[i][j] - '0';
    int ws = 0;
    REP(i,0,h) REP(j,0,w) ws += a[i][j];
    VVI ru(h+1,VI(w+1));
    REP(i,0,h) REP(j,0,w) ru[i+1][j+1] = ru[i+1][j] + a[i][j];
    REP(j,0,w) REP(i,0,h) ru[i+1][j+1] += ru[i][j+1];

    
    /*REP(i,0,h+1) {
        REP(j,0,w+1) cerr << ru[i][j] << " ";
        cerr << endl;
    }*/
    
    int ans = h * w;
    REP(p,0,1<<(h-1)) {
        int sum = countbits(p) - 1;
        VI ls;
        REP(i,0,h) if (p & (1 << i)) ls.push_back(i);
        ls.push_back(h-1);

        /*
        cerr << "ls: ";
        REP(i,0,ls.size()) cerr << ls[i] << " ";
        cerr << endl;
        */

        int last = 0;
        while (last < w) {
            int index;
            for (index = last + 1; index <= w; ++index) {
                int maxv = 0;
                REP(i,0,ls.size()) {
                    if (i == 0) {
                        int sum = ru[ls[i]+1][index] - ru[ls[i]+1][last] - ru[0][index] + ru[0][last];
                        chmax(maxv, sum);
                    } else {
                        int sum = ru[ls[i]+1][index] - ru[ls[i]+1][last] - ru[ls[i-1]+1][index] + ru[ls[i-1]+1][last];
                        chmax(maxv, sum);
                    }
                }
                //cerr << last << ", " << index << endl;
                //dump(maxv);
                if (maxv > k) break;
            }
            --index;
            if (index == last) {
                sum = h * w;
                break;
            }
            last = index;
            ++sum;
        }
        chmin(ans, sum);
    }
    cout << ans << endl;
    dump(ans);
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 384