#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // int T;cin>>T;while(T--) 
    {
        ll n,m,k;
        cin>>n>>m>>k;
        string s;
        ll a[n][m];
        ifr(i,0,n) {
            cin>>s;
            ifr(j,0,m) a[i][j] = (s[j]=='1');
        }
        ll cnt,ans=inf;
        ifr(mask,0,1<<(n-1)) {
        // ll mask = 0;
            cnt = __builtin_popcount(mask);
            cnt++;
            ll b[cnt]={0},ind=0,cut=0,temp[cnt]={0};
            vll v;
            ifr(i,0,n-1) if((mask>>i)&1) v.pb(i);
            v.pb(n);
            bool ff=0;
            ifr(j,0,m) {
                ind = 0;
                ifr(i,0,cnt) temp[i] = 0;

                ifr(i,0,n) {
                    if(v[ind]>=i) {
                        b[ind]+=a[i][j];
                        temp[ind]+=a[i][j];
                    } else {
                        ind++;
                        temp[ind]+=a[i][j];
                        b[ind]+=a[i][j];
                    }
                }
                bool f=0;
                ifr(i,0,cnt) {
                    if(b[i]>k) {
                        f=1;
                        cut++;
                        break;
                    }
                }
                // cout<<cut<<endl;
                // ifr(i,0,cnt) cout<<b[i]<<" "; cout<<endl;
                if(f) {
                    f=0;
                    ifr(i,0,cnt) if(temp[i]>k) {
                        f=1;
                        ff=1;
                        break;
                    }
                    if(f) break;
                    ifr(i,0,cnt) b[i] = temp[i];
                    // if(cnt-1+cut==1) {
                    //     cout<<cut<<endl;
                    //     cout<<mask<<endl;
                    // }
                }
                // ifr(i,0,cnt) cout<<b[i]<<" "; cout<<endl;
                // cout<<endl;
            }
            if(!ff) ans = min(ans,cnt-1+cut);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 384