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

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

#endif


#define mod 1000000007
typedef pair<int, int> P;
#define INF (1LL<<60)

void solve(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    vector<vector<int>> sum(H+1, vector<int>(W+1,0));
    rep(i,H)rep(j,W){
        sum[i+1][j+1] = sum[i][j+1] + sum[i+1][j] - sum[i][j] + (S[i][j]-'0');
    }
    
    int ans = INF;
    rep(bit, 1<<(H-1)){
        int tmpcut = 0;
        
        vector<int> Hcut;
        Hcut.push_back(0);
        rep(i,H-1) if(bit&(1<<i)) Hcut.push_back(i+1);
        Hcut.push_back(H);
        dump(bit, Hcut);
        
        tmpcut += Hcut.size()-2;
        
        int prevWcut=0;
        int cutcount = 0;
        for(int i=1; i<=W; i++){
            bool found=true;
            rep(j,Hcut.size()-1){
                int cnt = sum[Hcut[j+1]][i] - sum[Hcut[j]][i] - sum[Hcut[j+1]][prevWcut]
                    + sum[Hcut[j]][prevWcut];
//                dump(Hcut[j], Hcut[j+1], prevWcut, i, cnt);
                if(cnt > K){ found=false; break;}
            }
            if(found){
            }else{
                // このHcutパターンでは無理
                if(prevWcut+1==i){cutcount = 100000; break;}

                //                if(i<W){
                    cutcount++;
//                }
                prevWcut = i-1;
                dump(i-1);
            }
        }
        dump(bit, cutcount);
        tmpcut += cutcount;
        
        ans = min(ans, tmpcut);
    }
    cout << ans << endl;
    
}

signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 384