//E
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool G[20][1010];
int pre[20][1010];
int main(){
	int h,w,k;
	cin >> h >> w >> k;
	for(int i = 1;i <= h;i++){
		string s;
		cin >> s;
		for(int j = 0;j < w;j++){
			G[i][j+1] = s[j]-'0';
			pre[i][j+1] = pre[i][j] + G[i][j+1];
		}
	}
	ll ans = 1e17+10;
	int M = (1<<(h-1));
	for(int d = 0;d < M;d++){
		auto bit = bitset<31>(d);
		ll lst = 0,tans = 0,bcnt = 0;
		for(int i = 0;i < 30;i++)if(bit[i])bcnt++;
		for(int j = 1;j <= w;j++){
			ll cnt = 0,tcnt = 0;
			for(int i = 1;i <= h;i++){
				tcnt += pre[i][j] - pre[i][lst];
				if(bit[i-1]){
					cnt = max(cnt,tcnt);
					tcnt = 0; 
				}
			}
			cnt = max(cnt,tcnt);
			if(cnt > k){
				tans++;
				if(j-1 == lst){
					tans = 1e9;break;
				}
				lst = j-1;
			}
//			else if(cnt == k and j != w){
//				tans++;
//				if(lst == j){
//					tans = 1e9;break;
//				}
//				lst = j;
//			}
		}
		ans = min(ans,tans+bcnt);
//		cout << tans << " " << bcnt << endl;
	}
	cout << ans;
	return 0;
}
