#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Mat = vector<vector<int>>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int H,W,K;
Mat S,SumS;

Mat sumStoW(Mat SS){
    Mat res;
    for(auto s:SS){
        int n=s.size();
        vector<int> tmp(n+1,0);
        tmp[0] = 0;
        tmp[1] = s[0];
        for (int i = 1; i < n; i++)
        {
            tmp[i+1] = tmp[i]+s[i];
        }
       res.push_back(tmp);
    }
    return res;
}

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> H >> W >> K;
    S.assign(H,vector<int>(W,0));
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            S[i][j] = s[j]-'0';
        }
        
    }
    SumS = sumStoW(S);
}

int countOne(Mat s){
    int ans=0;
    for (int i = 0; i < s.size(); i++)
    {
        for (int j = 0; j < s[i].size(); j++)
        {
            ans += s[i][j];
        }
        
    }
    return ans;
}

// vector<int> bittovec(ll bit){
//     vector<int> res;
//     for (int i = 0; i < H; i++)
//     {
//         if((bit>>i)&1) res.push_back(i);
//     }
//     return res;    
// }

vector<int> sum_sub(vector<int> s, vector<int> t){
    vector<int> res;
    for (int i = 0; i < s.size(); i++)
    {
        res.push_back(s[i]+t[i]);
    }
    return res;
}

vector<int> sum_str(Mat s, vector<int> vech){
    vector<int> res(W+1,0);
    for(auto h:vech){
        res = sum_sub(res, s[h]);
    }
    return res;
}

bool isLess(Mat sums,int i,int j){
    for(auto ss:sums){
        if((ss[j]-ss[i])>K) return false;
    }
    return true;
}



int countColumnBar(Mat vecH){
    int cH = vecH.size();
    Mat sumS_putH(cH);
    for (int i = 0; i < cH; i++)
    {
        sumS_putH[i] = sum_str(SumS,vecH[i]);
    }
    int left=0;
    int j=1;
    DBG(sumS_putH)
    vector<int> w;
    while(j<=W) {
        if(isLess(sumS_putH,left,j)){
            j++;
            continue;
            }
        else{
            // ↓このケースはHの分け方がおかしい
            if((j-left)<=1) return INT_INF;
            // ↑このケースはHの分け方がおかしい
            w.push_back(j-1);
            left = j-1;
        }
    }
    DBG(w)
    return w.size();
}

int countColumnBar(ll bitH){
    auto bittovec = [&](ll bit){
        Mat res;
        vector<int> tmp;
        for (int i = 0; i < H; i++)
        {
            tmp.push_back(i);
            if((bit>>i)&1){res.push_back(tmp);tmp={};}
        }
        if(!tmp.empty()) res.push_back(tmp);
        return res;
    };
    Mat vec = bittovec(bitH);
    return countColumnBar(vec);
}

int countRowBar(ll bit){
    return __builtin_popcount(bit);
}

int solve(){
    int ans=H*W+100;
    for (ll bitH = 0; bitH < (1<<(H-1)); bitH++)
    {
        int cH = countRowBar(bitH);
        int cW = countColumnBar(bitH);
        DBG(cW)
        DBG(cH+cW)
        ans = min(ans,cH+cW);
    }
    cout << ans << endl;    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 512