//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
//----------------------------------------------------
int h, w, k;
int a[10][1000];
string str;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> h >> w >> k;
    forn(i, h){
        cin >> str;
        forn(j, w) a[i][j] = str[j] - '0';
    }
}


int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    int ans = INT32_MAX;
    vector<int> v, vv;
    forn(msk, (1 << h)){
        int cnt = bitcount(msk);
        v.resize(cnt+1), vv.resize(cnt+1);
        forn(kk, v.size()) v[kk] = 0;
        forn(i, w){
            forn(kk, vv.size()) vv[kk] = 0;
            int j = 0, jj = 0, mskk = msk;
            do{
                if(a[j][i] == 1) vv[jj]++;
                if(mskk & 1) jj++;
                j++;
                mskk >>= 1;
            }while(j < h);
            bool skip = false, fail = false;
            forn(kk, vv.size()){
                if(vv[kk] > k) {
                    cnt = INT32_MAX;
                    fail = true;
                    break;
                }else if(vv[kk] + v[kk] > k){
                    skip = true;
                    break;
                }else{
                    v[kk] += vv[kk];
                }
            }
            if(fail) break;
            if(skip){
                forn(kk, v.size()) v[kk] = vv[kk];
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256