#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
T meguru_search(T ok, T ng, function<bool(T)> check){
    while(max(ok, ng) - min(ok, ng) > T(1)){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int h, w, k;
    cin >> h >> w >> k;

    vector<string> s(h);
    rep(i, h){
        cin >> s[i];
    }

    vector< vector<int> > sum(h + 1, vector<int>(w + 1, 0));
    rep(i, h){
        rep(j, w){
            sum[i + 1][j + 1] = s[i][j] == '1';
        }
    }

    rep(i, h + 1){
        reps(j, w){
            sum[i][j] += sum[i][j - 1];
        }
    }

    reps(i, h){
        rep(j, w + 1){
            sum[i][j] += sum[i - 1][j];
        }
    }

    int ans = h * w;

    rep(bit, 1 << (h - 1)){
        int cnt = -1;
        rep(i, h - 1){
            cnt += bit >> i & 1;
        }
        for(int l = 0 ; l < w ; ){
            auto check = [&](int r){
                int prev = 0;
                rep(i, h - 1){
                    if(bit >> i & 1){
                        if(sum[i + 1][r] - sum[i + 1][l] - sum[prev][r] + sum[prev][l] > k){
                            return false;
                        }
                        prev = i + 1;
                    }
                }
                if(sum[h][r] - sum[h][l] - sum[prev][r] + sum[prev][l] > k){
                    return false;
                }
                return true;
            };

            int right = meguru_search<int>(l, w + 1, check);
            if(right == l){
                cnt = IINF;
                break;
            }
            ++cnt;
            l = right;
        }
        chmin(ans, cnt);
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 384