#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for (int i = 0; i < H; ++i) cin >> S[i];
  vector<vector<int>> cs(H + 1, vector<int>(W + 1));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cs[i + 1][j + 1] += S[i][j] - '0';
      cs[i + 1][j + 1] += cs[i + 1][j];
    }
  }
  for (int i = 0; i < H; ++i)
    for (int j = 0; j <= W; ++j) cs[i + 1][j] += cs[i][j];
  auto sum = [&](int t, int b, int l, int r) {
    return cs[b][r] - cs[b][l] - cs[t][r] + cs[t][l];
  };
  int ans = 1e9;
  for (int i = 0; i < (1 << (H - 1)); ++i) {
    vector<int> B(1, 0);
    for (int j = 0; j < H; ++j)
      if (i >> j & 1) B.push_back(j + 1);
    B.push_back(H);
    int cnt = B.size() - 2;
    int l = 0;
    for (int r = 0; r < W; ++r) {
      bool f = false;
      for (size_t j = 1; j < B.size(); ++j) {
        if (f) break;
        int t = B[j - 1], b = B[j];
        if (sum(t, b, l, r + 1) > K) {
          l = r;
          ++cnt;
          f = true;
          if (sum(t, b, l, r + 1) > K) {
            cnt = 1e9;
            break;
          }
        }
      }
      if (cnt >= 1e9) break;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
