#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
    long long h,w,k;
    cin >> h >> w >> k;
    vector<vector<int>> z(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        string q;
        cin >> q;
        for (int j = 0; j < w; j++) {
            z.at(i).at(j) = q.at(j)-48;
        }
    }
    int ans = 999999;
    for (int bit = 0; bit < (1 << h-1); ++bit) {
        int ok = 1;
        int count = 0;
        for (int j = 0; j < h - 1; j++) {
            if (bit & (1 << j))count++;
        }
        vector<vector<int>> p(h, vector<int>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                p.at(i).at(j) = z.at(i).at(j);
            }
         }
        
        for (int i = 0; i < w; i++) {
            int fl = 0;
            for (int j = 0; j < h - 1; j++) {
                if (!(bit & (1 << j))) {
                    p.at(j + 1).at(i) += p.at(j).at(i);
                    p.at(j).at(i) = 0;
                }
                else {
                    if (p.at(j).at(i) > k)ok = 0;
                    if (i != 0) {
                    if (p.at(j).at(i) + p.at(j).at(i - 1) > k) {
                        fl = 1;
                    }
                    }
                }
            }

            if (p.at(h - 1).at(i) > k)ok = 0;
            if (i != 0) {
                if (p.at(h - 1).at(i) + p.at(h - 1).at(i - 1) > k) {
                    fl = 1;
                }
                if (fl == 0) {
                    
                    for (int j = 0; j < h; j++) {
                        
                        p.at(j).at(i) += p.at(j).at(i - 1);
                        
                    }
                }
            }
            count += fl;
        }
        if (ok == 1)ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384