#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;
#define _min(a, b) (a > b ? b : a)
const int inf = 0x7FFFFFFF;
int pre_g[20][2000];
string g[20];
void out_put_g(int row, int col){
    for(int i = 1; i <= row; ++i){
        for(int j = 1; j <= col; ++j){
            cout << pre_g[i][j] << " ";
        }
        cout << endl;
    }
}
void get_pre_g(int row, int col){
    for(int i = 0; i < 2000; ++i){
        pre_g[0][i] = 0;
    }
    for(int i = 0; i < 20; ++i){
        pre_g[i][0] = 0;
    }
    for(int i = 1; i <= row; ++i){
        for(int j = 1; j <= col; ++j){
            pre_g[i][j] = pre_g[i - 1][j] + pre_g[i][j - 1] - pre_g[i - 1][j - 1];
            if(g[i][j] == '1'){
                pre_g[i][j]++;
            }
        }
    }
}
void ac(vector<int> &v){
    for(int i = 0; i < v.size(); ++i){
        v[i] = 0;
    }
}
bool check(vector<int> &v, int k){
    bool ok_flag = true;
    for(int i = 0; i < v.size(); ++i){
        if(v[i] > k){
            ok_flag = false;
            break;
        }
    }
    return ok_flag;
}
int query(pair<int, int> &p, int col){
    int i_a, j_a, i_b, j_b;
    i_a = p.first;
    j_a = col;
    
    i_b = p.second;
    j_b = col;
    int val = pre_g[i_b][j_b] - pre_g[i_a - 1][j_b] -
              (pre_g[i_b][j_a - 1] - pre_g[i_a - 1][j_a - 1]);
    return val;
}
int main(){
    int row, col, _k;
    cin >> row >> col >> _k;
    for(int i = 1; i <= row; ++i){
        g[i] = '-';
        string s;
        cin >> s;
        g[i] += s;
    }
    get_pre_g(row, col);
    // out_put_g(row, col);
    // cout << endl;
    pair<int, int> p;
    // p = make_pair(1, 2);
    // cout << "q:" << query(p, 1) << endl;
    int ans = inf;
    for(int i = 0; i < (1 << (row - 1)); ++i){
        vector<pair<int, int> > seg_v;
        int last_p = 1;
        for(int j = 1; j < row; ++j){
            if(i & (1 << (j - 1))){
                p = make_pair(last_p, j);
                seg_v.push_back(p);
                last_p = j + 1;
            }
        }
        p = make_pair(last_p, row);
        seg_v.push_back(p);

        vector<int> seg_cnt;
        // if(i == 0){
        //     cout << "seg_v.size() = " << seg_v.size() << endl;
        //     cout << "seg_v[0] = " << seg_v[0].first << " " << seg_v[0].second << endl;
        // }
        seg_cnt.resize(seg_v.size());
        ac(seg_cnt);
        int seg_s = seg_cnt.size();
        int cur = seg_cnt.size() - 1;
        int cur_col_length = 0;
        for(int j = 1; j <= col; ++j){
            for(int k = 0; k < seg_s; ++k){
                p = seg_v[k];
                seg_cnt[k] += query(p, j);
            }
            if(!check(seg_cnt, _k)){
                if(cur_col_length == 0){
                    cur = inf;
                    break;
                }
                for(int k = 0; k < seg_s; ++k){
                    p = seg_v[k];
                    seg_cnt[k] = query(p, j);
                }
                cur++;
                if(!check(seg_cnt, _k)){
                    cur = inf;
                    break;
                }
            }
            else{
                cur_col_length++;
            }
        }
        ans = _min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384