#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<class T>
struct CumulativeSum2D{
    vector<vector<T>> data;

    CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {}

    void add(int x, int y, T z){
        ++x, ++y;
        if(x >= data.size() || y >= data[0].size()) return;
        data[x][y] += z;
    }

    void build(){
        for(int i = 1; i < data.size(); ++i){
            for(int j = 1; j < data[i].size(); ++j){
                data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
            }
        }
    }

    T query(int sx, int sy, int gx, int gy){
        return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    CumulativeSum2D<int> sum(h, w);
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == '1')  sum.add(i, j, 1);
        }
    }
    sum.build();
    int ans = INF;
    for(int bit = 0; bit < (1 << (h - 1)); ++bit){
        vector<int> pos;
        pos.push_back(0);
        for(int i = 0; i < h - 1; ++i){
            if((bit >> i) & 1)  pos.push_back(i + 1);
        }
        pos.push_back(h);
        int sz = pos.size();
        vector<int> cnt(sz - 1, 0);
        int foo = sz - 2;
        bool ok = true;
        int width = 0;
        for(int i = 1; i <= w; ++i){
            bool update = false;
            for(int j = 0; j + 1 < sz; ++j){
                cnt[j] += sum.query(pos[j], i - 1, pos[j + 1], i);
                if(cnt[j] > k){
                    if(width == 0){
                        ok = false;
                        break;
                    }
                    ++foo;
                    update = true;
                    break;
                }
            }
            if(!ok) break;
            if(update){
                for(int j = 0; j + 1 < sz; ++j){
                    cnt[j] = sum.query(pos[j], i - 1, pos[j + 1], i);
                    if(cnt[j] > k){
                        ok = false;
                        break;
                    }
                }
                width = 1;
            }
            else    ++width;
        }
        if(!ok) continue;
        chmin(ans, foo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384