//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h, w, k, pref1[15][1111], pref2[15][1111], cur[1111];
bool a[15][1111];
main() {
  file("threesum");
  ios;
  cin >> h >> w >> k;
  fo(i, 1, h, 1) {
    fo(j, 1, w, 1) {
      char r;
      cin >> r;
      a[i][j] = (r == '1');
    }
  }
  int ans = INF1;
  auto solve = [&](int l, int r) {
    for (int i = l; i <= r; ++i){
      for (int j = 1; j <= w; ++j) {
        pref1[i][j] = pref1[i][j - 1] + a[i][j];
        pref2[i][j] = (i == l ? 0 :  pref2[i - 1][j]) + a[i][j];
      }
    }
    for (int j = 1; j <= w; ++j) {
      if (pref2[r][j] > k) return -1;
    }
    return 0;
  };
  for (int mask = 0; mask < (1 << (h - 1)); ++mask) {
    memset(pref1, 0, sizeof pref1);
    memset(pref2, 0, sizeof pref2);
    memset(cur, 0, sizeof cur);
    bool flag = 0;
    vi vec;
    vec.eb(0);
    for (int i = 0; i < h - 1; ++i) {
      if ((mask >> i) & 1) {
        vec.eb(i + 1);
      }
//        cerr << ((mask >> i) & 1);
    }
  //  cerr << "\n";
    vec.eb(h);
    int Res = 0;
    for (int i = 1; i < vec.size(); ++i) {
      int res = solve(vec[i - 1] + 1, vec[i]);
      if (res == -1) flag = 1;
    }
    if (flag) continue;
    for (int i = 1; i < vec.size(); ++i) cur[i] += pref2[vec[i]][1];
    fo(j, 2, w, 1) {
      flag = 0;
      for (int i = 1; i < vec.size(); ++i) {
        cur[i] += pref2[vec[i]][j];
        if (cur[i] > k) {
          flag = 1;
        }
      }
      if (flag) {
        ++Res;
        for (int i = 1; i < vec.size(); ++i) cur[i] = pref2[vec[i]][j];
      }
    }
//    cerr << bit(mask) << " " << Res  << "\n";
      chmin(ans, bit(mask) + Res);
  }
  cout << ans;
  return 0;
}
/**

*/


Measured memory_bytes: 384