#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll h, w, k;	cin >> h >> w >> k;
	vector <string> a(h);	
	for (ll i = 0; i < h; i ++)	cin >> a[i];

	ll result = 1e9;
	for (ll bs = 0; bs <= (1 << (h - 1)); bs ++)
	{	
		ll st = __builtin_popcount(bs);
		vector <ll> cur(st + 1);
		ll r = st;

		bool stuck = false;
		for (ll i = 0; i < w; i ++)
		{
			ll now = 0;

			for (ll j = 0; j < h; j ++){
				if (a[j][i] == '1') cur[now] += 1;
				if ((bs >> j) & 1)	now += 1;
			}

			if (*max_element(cur.begin(), cur.end()) > k){
				if (stuck){
					r = 1e9;
					break;
				}
				r += 1;
				for (auto &x : cur)	x = 0;
				i -= 1;
				stuck = true;
				continue;
			}
			stuck = false;
		}
		result = min(result, r);
	} 
	cout << result << "\n";
}