#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
 
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readc(h, w, k);
	char ch[h + 1][w + 1] ={};
	int dp[h + 1][w + 1] = {}, sum[h + 1][w + 1] = {};
	FOR (i, 1, h)
        FOR (j, 1, w)
            cin >> ch[i][j];
    
    FOR (i, 1, h)
        FOR (j, 1, w)
        {
            sum[i][j] = sum[i -1][j] + sum[i][j - 1] - sum[i-1][j - 1];
            if (ch[i][j] == '1') sum[i][j]++; 
        }
    
    int ans = inf;
	FOR (pig, 0, (1 << (h-1)) - 1)
	{
	    set <int> cuts;
	    int copy = pig;
	    
	    FOR (j, 0, h-2)
	    {
	        bool bit = copy & 1;
	        if (bit) cuts.insert(j+1);
	        copy /= 2;
	    }
	    
	    int head[12] = {};
	    for (int i: cuts) head[i + 1] = i;
	    
	    int prev = 0;
	    FOR (i, 1, h)
	    {
	        if (head[i]) prev = head[i];
	        head[i] = prev;
	    }
	    
	    int cnt = 0, p[12] = {};
	    FOR (j, 1, w)
	    {
	        bool meow = 0;
	        FOR (i, 1, h)
	        {
	            if (ch[i][j] == '1') p[head[i]]++; 
	            if (p[head[i]] > k) meow = 1;
	        }
	        
	        if (meow)
	        {
	            FOR (i, 1, h) p[head[i]] = 0;
	            cnt++;
	            
	            int bhow = 0;
	            FOR (i, 1, h)
    	        {
    	            if (ch[i][j] == '1') p[head[i]]++; 
    	            if (p[head[i]] > k) bhow = 1;
    	        }
    	        
    	        if (bhow) goto uff;
	        }
	        
	        //FOR (i, 1, h) cout << p[head[i]]; cout << endl;
	        //cout << pig << " " << j << ": "  << cnt << endl;
	    }
	    
	    ans = min(ans, cnt + __builtin_popcount(pig));
	    uff:;
	    
	}
	
	cout << ans;
}















Measured memory_bytes: 512