#include<bits/stdc++.h>
using namespace std;
 
/* data type, special numbers, defines */
//#define int ll //use if ded
#define ll long long
#define ld long double
const ll inf=LLONG_MAX;
//const ll mod=1e9+7;
const ll mod=998244353;
const ld pi=acos(-1.0);
#define all(v) v.begin(), v.end()
/* end data type and special numbers */
 
/* fast input.output */
#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define endl pc('\n')
int get_i(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	int rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=(rs<<1)+(rs<<3)+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
ll get_l(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	ll rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=rs*10ll+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
string get_s(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	string s=""; s+=c; c=gc();
	for(; 33<=c && c<=126; c=gc())
		s+=c;
	return s;
}
char get_c(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	return c;
}
void print_i(int _n){
	bool neg=false; if(_n<0) {neg=true; _n=-_n;}
	if(neg) pc('-');
	int N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=(rev<<3)+(rev<<1)+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_l(ll _n){
	ll N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=rev*10ll+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_s(string a){
	for(int i=0; i<a.size(); i++)
		pc(a[i]);
}
#define endline pc('\n');
#define space pc(' ');
/* end fast input/output */

/*   E N D   O F   T E M P L A T E   */

int n, m, k, a[15][1005], pref[15][1005];
int main(){
	n=get_i(), m=get_i(), k=get_i();
	for(int i=0; i<n; i++){
		string s=get_s();
		for(int j=0; j<m; j++)
			a[i][j]=s[j]-'0';
	}
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			if(i==0)
				if(j==0) pref[i][j]=a[i][j];
				else pref[i][j]=pref[i][j-1]+a[i][j];
			else
				if(j==0) pref[i][j]=pref[i-1][j]+a[i][j];
				else pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
	vector<int>v; int ans=1e9;
	for(int mask=0; mask<(1<<(n-1)); mask++){
	//	print_s("MASK: "); print_i(mask); endline
		v.clear(); v.push_back(0);
		for(int j=0; j<n-1; j++){
			if(mask&(1<<j)) v.push_back(j+1);
		}
		int len=v.size();
		v.push_back(n);
	//	print_s("HORIZONTAL\n");
	//	for(int i:v){
	//		print_i(i); space
	//	}
	//	endline
		int latest=0;
		int cnt=0;
		for(int i=1; i<=m; i++){
			bool cuthere=false;
		//	print_s("CUTTING HERE: "); print_i(i); print_s(":\n");
			for(int j=0; j<len; j++){
				int sum;// print_i(v[j]); space print_i(v[j+1]-1); print_s(": ");
				if(j==0){
					sum=pref[v[j+1]-1][i-1];
					if(latest!=0) sum-=pref[v[j+1]-1][latest-1];
				}else{
					sum=pref[v[j+1]-1][i-1]-pref[v[j]-1][i-1];
					if(latest!=0) sum-=pref[v[j+1]-1][latest-1]-pref[v[j]-1][latest-1];
				}
		//		print_i(sum); endline
				if(sum>k){
					cuthere=true; break;
				}
			}
			if(cuthere){
				if(i-1==latest){cnt=1e9; break;}
				latest=i-1; i--;
				cnt++;
			}
		}
		ans=min(ans, len+cnt-1);
	//	print_i(ans); endline;
	}
	print_i(ans); endline return 0;
}

Measured memory_bytes: 384