#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

const int INF = 10000;

// TODO: implement
int main() {
  // input
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  int ans = INF;
  rep(div, 1 << (h - 1)) {
    // format data
    vector<int> id(h);
    int g = 0;
    int count[h][w];
    rep(i, h) rep(j, w) count[i][j] = 0;
    rep(i, h) {
      rep(j, w) count[g][j] += s[i][j] - '0';
      if (div >> i & 1) g++;
    }
    g++;

    // devid vertically
    int now = g - 1;
    int sum[g];
    rep(i, g) sum[i] = 0;
    rep(j, w) {
      rep(i, g) {
        if (count[i][j] > k) {
          now = INF;
          break;
        }
      }
      rep(i, g) sum[i] += count[i][j];
      rep(i, g) {
        if (sum[i] > k) {
          now++;
          rep(i, g) sum[i] = count[i][j];
        }
      }
    }
    ans = min(ans, now);
  }
  cout << ans << endl;

  return 0;
}
