#include <bits/stdc++.h>
using namespace std;
const int N=1010;
const int M=12;
const int INF=1e9;
int h,w,k;
int pre[M][N];
inline int calc(int x11,int y11,int x22,int y22) {
	return pre[x22][y22]-pre[x11-1][y22]-pre[x22][y11-1]+pre[x11-1][y11-1];
}
int check(int i,int left,int j) {
	int cnt=0,i1;
	for (i1=0;i1<h;i1++) {
		cnt+=calc(i1+1,left,i1+1,j);
		if (cnt>k) return 0;
		if ((i>>i1)&1==1) cnt=0;
	}
	return 1;
}
int main() {
	int left,flag,i,j,ans,cnt;
	string s;
	cin>>h>>w>>k;
	for (i=1;i<=h;i++) {
		cin>>s;
		for (j=1;j<=w;j++)
			pre[i][j]=s[j-1]-'0'+pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
	}
	ans=INF;
	for (i=0;i<(1<<(h-1));i++) {
		cnt=0;
		for (j=0;j<h-1;j++)
			if ((i>>j)&1==1) cnt++;
		left=1; flag=1; j=1;
		while (j<=w) {
			while (j<=w&&check(i,left,j)) j++;
			if (j>w) break;
			if (j==left) {
				flag=0; break;
			}
			cnt++; if (cnt>ans) break;
			left=j;
		}
		if (flag&&cnt<ans) ans=cnt;
//		cout<<i<<' '<<cnt<<endl;
	}
	cout<<ans<<endl;
	return 0;
}