#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int h, w, k, team[50], val[50][1100];
char mat[50][1100];
int makeTeam(int x) {
  vector<int> a;
  for (int i = 0; i <= h - 2; ++i) {
    if (x & (1 << i)) {
      a.emplace_back(i);
    }
  }
  int tot = 1;
  if (!((int)(a).size())) {
    for (int i = 0; i < (int)(h); ++i) team[i] = 1;
  } else {
    int len = ((int)(a).size());
    for (int i = 0; i <= a[0]; ++i) team[i] = tot;
    ++tot;
    for (int i = 0; i < len - 1; ++i) {
      for (int j = a[i] + 1; j <= a[i + 1]; ++j) {
        team[j] = tot;
      }
      ++tot;
    }
    for (int i = a[len - 1] + 1; i < h; ++i) team[i] = tot;
  }
  return tot;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  cin >> h >> w >> k;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> mat[i][j];
      val[i][j] = int(mat[i][j] - '0');
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < (1 << (h - 1)); ++i) {
    memset(team, -1, sizeof(team));
    int cnt = makeTeam(i) - 1;
    int now[50];
    memset(now, 0, sizeof(now));
    bool impossible = false;
    int pref = 0;
    for (int j = 0; j < w; ++j) {
      for (int o = 0; o < h; ++o) {
        now[team[o]] += val[o][j];
        if (now[team[o]] > k) {
          memset(now, 0, sizeof(now));
          ++cnt;
          --j;
          if (pref == j) impossible = true;
          pref = j;
          break;
        }
      }
      if (impossible) break;
    }
    if (!impossible) ans = min(ans, cnt);
  }
  cout << ans << '\n';
  return 0;
}
