#include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

vector<vi> arr, pref;

int get_sum(int rs, int re, int cs, int ce) {
    rs--; cs--;

    int res = pref[re][ce];
    if(rs >= 0 && cs >= 0) res += pref[rs][cs];
    if(rs >= 0) res -= pref[rs][ce];
    if(cs >= 0) res -= pref[re][cs];
    return res;
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    clock_t clk = clock();

    int h,w,k; cin>>h>>w>>k;
    arr.resize(h, vi(w)); pref.resize(h, vi(w));
    FOR(i, 0, h) {
        FOR(j, 0, w) {
            char c; cin>>c;
            arr[i][j] = c - '0';
            pref[i][j] = arr[i][j];
            if(j) pref[i][j] += pref[i][j-1];
            if(i) pref[i][j] += pref[i-1][j];
            if(i && j) pref[i][j] -= pref[i-1][j-1];
            // cout<<pref[i][j]<<" ";
        }
        // cout<<endl;
    }
    int res = INF;

    FOR(mask, 0, (1 << (h - 1))) {
        vi cuts; cuts.pb(-1);
        FOR(i, 0, 9) {
            if(mask & (1 << i)) cuts.pb(i); // for cut after row 0, cuts will have 0 as an entry.
        }
        int cnt = cuts.size() - 1, start = 0; 
        cuts.pb(h-1); // just to make things easier
        // FOR(i, 0, cuts.size()) cout<<cuts[i]<<" ";
        // cout<<endl;
        bool imposs = false;
        while(start < w) {
            int farthest = INF;
            FOR(ci, 1, (int)cuts.size()) {
                int rs = cuts[ci - 1] + 1; int re = cuts[ci];
                assert(rs <= re);

                int lo = start, hi = w - 1; int currbest = -1;
                while(lo <= hi) {
                    int mid = (lo + hi) >> 1;

                    if(get_sum(rs, re, start, mid) <= k) {
                        currbest = max(currbest, mid);
                        lo = mid + 1;
                    } else hi = mid - 1;
                }
                farthest = min(farthest, currbest);
            }
            if(farthest == -1) {
                imposs = true; break;
            } // not possible to work with this cut.
            if(farthest + 1 < w)
                cnt++; // cut at "farthest" column.
            start = farthest + 1;
            // deb(start);
        }
        if(imposs) continue;
        res = min(res, cnt);
    }
    cout<<res;
    cerr << endl << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << endl;
    return 0;
}

Measured memory_bytes: 384