#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int h, w, k, ans = 2000;
char s[12][1005];
int main(){
	scanf("%d%d%d", &h, &w, &k);
	rep(i,h) scanf("%s", s[i]);
	rep(bt, 1<<(h-1)){
		int n = __builtin_popcount(bt)+1, dp[12] = {}, cnt = n-1;
		bool ok = true;
		rep(i,w){
			int nw[12] = {}, e = 0;
			bool f = false;
			rep(j,h){
				if(s[j][i] == '1') nw[e]++;
				if((bt>>j)&1) e++;
			}
			rep(j,n) if(dp[j] + nw[j] > k){
				f = true;
				if(nw[j] > k) ok = false;
			}
			if(f){
				cnt++;
				rep(j,n) dp[j] = nw[j];
			}else rep(j,n) dp[j] += nw[j];
		}
		if(ok) ans = min(ans, cnt);
	}
	printf("%d\n", ans);
}
