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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 2e5+3;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    int n, m, k;
    cin>>n>>m>>k;
    vvi a(n+1, vi(m+1));
    for(int i=1; i<=n; i++) {
        string s;
        cin>>s;
        for(int j=1; j<=m; j++) {
            a[i][j] = s[j-1]-'0';
        }
    }
    vvi pref(n+1, vi(m+1));
    for(int j=1; j<=m; j++) {
        for(int i=1; i<=n; i++) {
            pref[i][j] = a[i][j] + pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
        }
    }
    auto get_sum = [&](int r1, int r2, int c1, int c2)
    {
        return pref[r2][c2] - pref[r1][c2] - pref[r2][c1] + pref[r1][c1];
    };
    int ans = inf;
    for(int mask=0; mask < (1<<(n-1)); mask++) {
        vi row{0};
        int res = bitcount(mask);
        for(int j=0; j<n-1; j++) {
            if(mask&(1<<j)) {
                row.PB(j+1);
            }
        }
        row.PB(n);
        vi col{0};
        for(int j=1; j<=m; j++) {
            for(int i=1; i<row.size(); i++) {
                int r1 = row[i-1], r2= row[i];
                int c1 = col.back(), c2 = j;
                int cur = get_sum(r1, r2, c1, c2);
                if(cur > k) {
                    if(c1==c2-1) {
                        res = inf;
                        break;
                    }
                    else {
                        col.PB(c2-1);
                        res++;
                    }
                }
            }
        }
        col.PB(m);
        for(int i=1; i<row.size(); i++) {
            int r1 = row[i-1], r2= row[i];
            for(int j=1; j<col.size(); j++) {
                int c1 = col[j-1], c2 = col[j];
                int cur = get_sum(r1, r2, c1, c2);
                if(cur > k) {
                    res = inf;
                    break;
                }
            }
        }
        ans = min(ans, res);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 512