#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcd(long long a, long long b) {
  if (b == 0) return a;
  return (a / gcd(a, b)) * b;
}
vector<int> divnum(long long num) {
  int dig;
  vector<int> p;
  while (num) {
    dig = num % 10;
    p.push_back(dig);
    num /= 10;
  }
  return p;
}
int digiter(long long num) {
  int dig;
  vector<int> p;
  while (num) {
    dig = num % 10;
    p.push_back(dig);
    num /= 10;
  }
  return p.size();
}
vector<int> convert(string s) {
  vector<int> d;
  long long n = s.size();
  for (int i = 0; i < n; i++) {
    d.push_back(s[i] - '0');
  }
  return d;
}
int H, W, K;
string S[100];
int c[10][10000];
int main() {
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int ans = (1e9);
  for (int div = 0; div < (1 << (H - 1)); div++) {
    int g = 0;
    int num = 0;
    vector<int> id(H);
    for (int row = 0; row < H; row++) {
      id[row] = g;
      if ((div >> row) & 1) {
        g++;
      }
    }
    g++;
    for (int i = 0; i < g; i++)
      for (int j = 0; j < W; j++) c[i][j] = 0;
    for (int i = 0; i < H; i++)
      for (int j = 0; j < W; j++) c[id[i]][j] += (S[i][j] - '0');
    num = g - 1;
    vector<int> now(g);
    auto add = [&](int j) {
      for (int i = 0; i < g; i++) {
        now[i] += c[i][j];
        if (now[i] > K) return false;
      }
      return true;
    };
    for (int j = 0; j < W; j++) {
      if (!add(j)) {
        num++;
        now = vector<int>(g);
        if (!add(j)) {
          num = (1e9);
          break;
        }
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}
