// Contest: AtCoder Beginner Contest 159 (https://atcoder.jp/contests/abc159)
// Problem: E: Dividing Chocolate (https://atcoder.jp/contests/abc159/tasks/abc159_e)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

template <class T, size_t... Is> struct arr_helper;
template <class T> struct arr_helper<T> { using type = T; };
template <class T, size_t I, size_t... Is>
struct arr_helper<T, I, Is...> { using type = array<typename arr_helper<T, Is...>::type, I>; };
template <class T, size_t... Is> using arr = typename arr_helper<T, Is...>::type;

arr<bool, 10, 1000> s;

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

    int h, w, k; cin >> h >> w >> k;
    rep(i, h) {
        string _s; cin >> _s;
        rep(j, w)
            s[i][j] = _s[j] == '1';
    }

    int mn = INF;
    for (u32 m = 0; m < (1u << (h - 1)); ++m) {
        vi cnt(__builtin_popcount(m) + 1);
        vi group(h), newcnt(sz(cnt));
        rep(i, h - 1)
            if ((m >> i) & 1)
                reps(j, i + 1, h)
                    group[j]++;
        int cuts = 0;
        rep(i, w) {
            fill(all(newcnt), 0);
            rep(j, h)
                newcnt[group[j]] += s[j][i];
            bool large = false;
            trav(j, newcnt)
                large |= j > k;
            if (large) {
                cuts = INF;
                break;
            }
            bool merge = true;
            rep(j, sz(cnt))
                merge &= cnt[j] + newcnt[j] <= k;
            if (merge) {
                rep(j, sz(cnt))
                    cnt[j] += newcnt[j];
            } else {
                ++cuts;
                rep(j, sz(cnt))
                    cnt[j] = newcnt[j];
            }
        }
        mn = min(mn, cuts + __builtin_popcount(m));
    }

    cout << mn << '\n';
    return 0;
}

Measured memory_bytes: 256