/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,k;
    cin>>h>>w>>k;
    ll fires=1e18;
    VV vec(h,V(w));
    rep(i,h){
        string s;
        cin>>s;
        rep(j,w){
            vec[i][j]=s[j]-'0';
        //    cout<<vec[i][j]<<" ";
        }
       // cout<<endl;
    }
    ll h2=h-1;
    rep(bit,(1<<h2)){
       // cout<<bit<<endl;
        V temp1;
        ll num=__builtin_popcount(bit);
        rep(j,h2){
            if(bit&(1<<j)){
                temp1.push_back(1);
            }else{
                temp1.push_back(0);
            }
        }
        VV cnt(num+1,V(w));
        
       // cout<<num+1<<endl;
       // cout<<"hi"<<endl;
        rep(i,w){
            ll tempsum=vec[0][i];
            ll index=0;
            rep(j,h2){
                if(temp1[j]){
                    cnt[index][i]=tempsum;
                    tempsum=vec[j+1][i];
                    index++;
                }else{
                    tempsum+=vec[j+1][i];
                  //  cout<<j+1<<" "<<i<<" "<<tempsum<<endl;
                }
            }
            cnt[index][i]=tempsum;
        }
        /*rep(i,num+1){
            rep(j,w){
                cout<<cnt[i][j]<<" ";
            }
            cout<<endl;
        }
        cout<<endl;*/
        ll res=num;
        num++;
        bool f2=false;
        rep(i,num){
            rep(j,w){
                if(cnt[i][j]>k){
                    f2=true;
                    break;
                }
            }
        }
        if(f2)continue;
        rep3(i,1,w){
            bool f=false;
            rep(j,num){
                if(cnt[j][i]+cnt[j][i-1]>k){
               //     cout<<j<<" "<<i<<" 引っかかった"<<cnt[j][i]+cnt[j][i-1]<<endl;
                    f=true;
                    break;
                }
            }
            if(f){
                res++;
            }else{
                rep(j,num){
                    cnt[j][i]+=cnt[j][i-1];
                }
            }
        }
      //  cout<<res<<endl;
        chmin(fires,res);
    }
    cout<<fires<<endl;
}


Measured memory_bytes: 384