#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  int H, W, K;
  std::cin >> H >> W >> K;

  std::vector<std::vector<char>> S(H, std::vector<char>(W));
  for (int i = 0; i < H; ++i)
    for (int j = 0; j < W; ++j)
      std::cin >> S[i][j];

  // 行毎の累積和
  std::vector<std::vector<int>> sum(H, std::vector<int>(W + 1, 0));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      sum[i][j + 1] = sum[i][j] + (S[i][j] - '0');
    }
  }
  // 行 i の [l, r) の和は sum[i][r] - sum[i][l] となる

  // std::cout << sum << std::endl;

  int allres = IINF;

  int N = H - 1; // 区切りの個数
  for (int k = 0; k < (1 << N); ++k) {
    std::vector<bool> bit(N, false);
    for (int i = 0; i < N; ++i)
      if (k & (1 << i))
        bit[i] = true;

    // NOTE: `bit[i] == true` <=> i と i+1 を区切る

    // std::cout << "bit: " << bit << std::endl;

    std::vector<int> rs;

    bool allok = true;
    int l = 0;
    for (int r = 1; r <= W; ++r) {
      std::vector<int> x(H, 0);
      for (int i = 0; i < H; ++i)
        x[i] = sum[i][r] - sum[i][l];

      // std::cout << r << ": " << x << std::endl;

      bool ok = true;
      int tmp = 0;
      for (int i = 0; i < H; ++i) {
        tmp += x[i];
        if (i == H - 1) {
          if (tmp <= K) {
            tmp = 0;
            continue;
          } else {
            rs.push_back(r - 1);
            ok = false;
            break;
          }

        } else if (bit[i] == false) {
          continue;
        } else {          // 区切り
          if (tmp <= K) { // OK
            tmp = 0;
            continue;
          } else {
            rs.push_back(r - 1);
            ok = false;
            break;
          }
        }
      }

      if (ok) {
        continue;
      } else {
        if (l == rs.back()) {
          allok = false;
          break; // 失敗
        } else {
          l = rs.back();
          continue;
        }
      }
    }

    // std::cout << "  rs: " << rs << std::endl;

    if (not allok) {
      continue;
    } else {
      int res = rs.size();
      for (int i = 0; i < H - 1; ++i) {
        if (bit[i]) {
          res += 1;
        }
      }

      chmin(allres, res);
    }
  }

  std::cout << allres << std::endl;

  return 0;
}


Measured memory_bytes: 256