#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long h, w, k; cin >> h >> w >> k;
	vector<string> choc(h + 1);
	for (long long i = 1; i <= h; i++) cin >> choc[i], choc[i] = "*" + choc[i];

	vector<vector<long long>> pref(h + 1, vector<long long>(w + 1, 0));

	for (long long i = 1; i <= h; i++) {
		for (long long j = 1; j <= w; j++) pref[i][j] = ((choc[i][j] == '1') + pref[i][j - 1]);
	}

	debug(choc, pref);
	long long min_ans = LLONG_MAX;
	long long lim = 1 << (h - 1);

	for (long long mask = 0; mask <= lim - 1; mask++) {

		long long prev = 1;
		long long ans = 0;

		for (long long j = 1; j <= w; j++) {

			long long curr_white = 0;
			long long curr_max_white = 0;
			long long curr_col_cnt=0;
			long long curr_col_max=0;

			for (long long curr = 1; curr <= h; curr++) {
				curr_white += (pref[curr][j] - pref[curr][prev - 1]);
				curr_col_cnt+=(choc[curr][j]=='1');
				if ((((mask) & (1 << (curr - 1))) != 0) or curr == h) {
					debug(mask, j, curr, (1 << (curr - 1)), curr_white);
					curr_max_white = max(curr_max_white, curr_white);
					curr_col_max=max(curr_col_max,curr_col_cnt);
					curr_col_cnt=0;
					curr_white = 0;
				}
			}
			if(curr_col_max > k) ans=h*w;
			if (curr_max_white > k) prev = j, ans++;
		}
		// cout<<(bitset<4>(mask))<<" "<< ans + __builtin_popcount(mask)<<endl;
		// debug(bitset<4>(mask), ans + __builtin_popcount(mask));
		min_ans = min(min_ans, ans + __builtin_popcount(mask));
	}

	cout << min_ans;
	return 0;
}

Measured memory_bytes: 384