#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int h, w, K;
bool **a;

char getByte() {
	char c = getchar();
	while (c != '0' && c != '1') {
		c = getchar();
	}
	return c;
}

vector<int> cutInt(int x) {
	vector<int> res;
	int k = 0;
	while (x > 0) {
		if (x & 1) {
			res.push_back(k);
		}
		++k; x /= 2;
	}
	return res;
}

int main() {
	cin >> h >> w >> K;
	a = new bool*[h];
	for (int x = 0; x < h; ++x) {
		a[x] = new bool[w];
		for (int y = 0; y < w; ++y) {
			char c = getByte();
			a[x][y] = (c == '1');
		}
	}
	int ans = h + w;
	for (int s = 0; s < (1 << (h - 1)); ++s) {
		vector<int> cuts = cutInt(s); // cut after x

		// for (int i = 0; i < cuts.size(); ++i) {
		// 	cout << cuts[i] << ' ';
		// }
		// cout << endl;

		vector<int> counts, tmp;
		int k = cuts.size();
		int nans = cuts.size();
		for (int i = 0; i <= k; ++i) {
			counts.push_back(0);
			tmp.push_back(0);
		}
		bool flag = true;
		for (int i = 0; i < w; ++i) {
			bool addCut = false;
			int cur = 0;
			for (int j = 0; j < tmp.size(); ++j) {
				tmp[j] = 0;
			}
			for (int j = 0; j < h; ++j) {
				if (cur < k && j > cuts[cur]) {
					++cur;
				}
				if (a[j][i]) {
					tmp[cur] += 1;
				}
			}
			for (int j = 0; j <= k; ++j) {
				if (tmp[j] > K) {
					flag = false;
					break;
				}
				if (tmp[j] + counts[j] > K) {
					addCut = true;
				}
			}
			if (addCut) {
				++nans;
			}
			for (int j = 0; j <= k; ++j) {
				if (addCut) {
					counts[j] = tmp[j];
				}
				else {
					counts[j] += tmp[j];
				}
			}
		}
		// cout << "ans = " << nans << endl;
		if (flag) {
			ans = min(ans, nans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256