#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int H, W, K;
    vector<vector<Int>> A;

    Int calc(uInt mask) {
        Int ret = __builtin_popcount(mask);
        vector<Int> kireme;
        kireme.push_back(-1);
        for (int i = 0; i + 1 < H; ++i) {
            if (mask >> i & 1) {
                kireme.push_back(i);
            }
        }
        kireme.push_back(H - 1);

        vector<vector<Int>> vv;
        for (int i = 0; i + 1 < kireme.size(); ++i) {
            vector<Int> vec;
            for (Int w = 0; w < W; ++w) {
                vec.push_back(0);
                for (Int h = kireme[i] + 1; h <= kireme[i + 1]; ++h) {
                    vec.back() += A[h][w];
                }
            }

//            Int cnt = 0;
//            for (int j = 0, k = 0; j < vec.size() && k <= vec.size();) {
//                if (j == k && vec[k] > K) return -1;
//                if (cnt + vec[k] > K) {
//                    ret++;
//                    cnt = 0;
//                    j = k;
//                    continue;
//                }
//
//                cnt += vec[k];
//                k++;
//            }
            vec.push_back(0);
            vv.push_back(vec);
        }


        for (int i = 0; i < vv.size(); ++i) {
            for (int j = 0; j < vv[i].size(); ++j) {
                if (vv[i][j] > K) return -1;
            }
        }

        vector<Int> cnt(vv.size());
        for (int j = 0, k = 0; j < vv[0].size() && k < vv[0].size();) {
            bool f = false;
            for (int i = 0; i < vv.size(); ++i) {
                if (cnt[i] + vv[i][k] > K) {
                    f = true;
                }
            }
            if (f) {
                ret++;
                fill(all(cnt), 0);
                j = k;
                continue;
            }

            for (int i = 0; i < cnt.size(); ++i) {
                cnt[i] += vv[i][k];
            }
            k++;
//            if (cnt + vec[k] > K) {
//                ret++;
//                cnt = 0;
//                j = k;
//                continue;
//            }
//
//            cnt += vec[k];
//            k++;
        }

        return ret;
    }

    void solve() {
        cin >> H >> W >> K;
        A.resize(H, vector<Int>(W));
        for (int i = 0; i < H; ++i) {
            string s;
            cin >> s;
            for (int j = 0; j < W; ++j) {
                A[i][j] = s[j] - '0';
            }
        }

        Int ans = INFl;
        calc(2);
        for (int i = 0; i < 1ll << (H - 1); ++i) {
            Int tmp = calc(i);
            if (tmp != -1) {
//                if (ans > tmp) {
//                    chmin(ans, tmp);
//                }
                chmin(ans, tmp);
            }

        }
        cout << ans << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 1144