#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
typedef vector<ll> row;
typedef vector<row> matrix;
const int N = 1e3 + 9;
int  aux[N][11];
matrix mat;
int n, m;
void preProcess()
{
    // Copy first row of mat[][] to aux[][] 
    for (int i = 0; i < m; i++)
        aux[0][i] = mat[0][i];

    // Do column wise sum 
    for (int i = 1; i < n; i++)
        for (int j = 0; j < m; j++)
            aux[i][j] = mat[i][j] + aux[i - 1][j];

    // Do row wise sum 
    for (int i = 0; i < n; i++)
        for (int j = 1; j < m; j++)
            aux[i][j] += aux[i][j - 1];
}

// A O(1) time function to compute sum of submatrix 
// between (tli, tlj) and (rbi, rbj) using aux[][] 
// which is built by the preprocess function 
int sumQuery(int tli, int tlj, int rbi,
    int rbj)
{
    // result is now sum of elements between (0, 0) and 
    // (rbi, rbj) 
    int res = aux[rbi][rbj];

    // Remove elements between (0, 0) and (tli-1, rbj) 
    if (tli > 0)
        res = res - aux[tli - 1][rbj];

    // Remove elements between (0, 0) and (rbi, tlj-1) 
    if (tlj > 0)
        res = res - aux[rbi][tlj - 1];

    // Add aux[tli-1][tlj-1] as elements between (0, 0) 
    // and (tli-1, tlj-1) are subtracted twice 
    if (tli > 0 && tlj > 0)
        res = res + aux[tli - 1][tlj - 1];

    return res;
}
matrix zero(int n, int m) {
    return matrix(n, row(m, 0));
}
matrix initial(int n, int m, int val = 0) {
    return matrix(n, row(m, val));
}
matrix rotate(matrix v) {
    matrix r = zero(sz(v[0]), sz(v));
    for (int i = 0; i < sz(v); i++) {
        for (int j = 0; j < sz(v[0]); j++)
            r[j][sz(v) - i - 1] = v[i][j];
    }
    return r;
}
int main() {
	//file();
	fast();
    int k; cin >> n >> m >> k;
    mat = initial(n, m);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            char ch; cin >> ch;
            mat[i][j] = ch - '0';
        }
    }
    mat = rotate(mat);
    swap(n, m);
    preProcess();
    int ans = INT_MAX;
    for (int w = 0; w < (1 << m - 1); w++) {
        vi v1;
        for (int j = 0; j < m - 1; j++)
            if (w & (1 << j))
                v1.push_back(j);
        v1.push_back(m - 1);
        int last = 0;
        int cnt = sz(v1) - 1;
        for (int i = 0; i < n; i++) {
            int lastCol = 0;
            bool ok = 1;
            for (auto& it : v1) {
                if (sumQuery(last, lastCol, i, it) > k) {
                    ok = 0;
                    break;
                }
                lastCol = it + 1;
            }
            if (!ok && last == i) {
                cnt = 1e9;
                break;
            }
            if (!ok) {

                cnt++;
                last = i;
            }
        }
        if (cnt == 1e9) continue;
        int lastCol = 0;
        bool ok = 1;
        for (auto& it : v1) {
            if (sumQuery(last, lastCol, n - 1, it) > k) {
                ok = 0;
                break;
            }
            lastCol = it + 1;
        }
        if (ok)
            ans = min(ans, cnt);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640