#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

// 2-dimention
class CumulativeSum {
  private:
    int H_, W_;
    std::vector<std::vector<long long>> s;

  public:
    explicit CumulativeSum (int H, int W) : H_(H), W_(W) {
      s.resize(H+1); for(int i=0; i<=H; i++) s[i].resize(W+1);
      s[0][0] = 0;
      for(int i=0; i<=H_; i++) s[i][0] = 0;
      for(int i=0; i<=W_; i++) s[0][i] = 0;
    }

    void set(int i, int j, long long a) {
      s[i+1][j+1] = a;
      return;
    }

    void build() {
      for(int i=0; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] += s[i][j-1];
      for(int i=1; i<=H_; i++) for(int j=0; j<=W_; j++) s[i][j] += s[i-1][j];
    }

    void build ( const std::vector<std::vector<long long>> &a ) {
      for(int i=1; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] = a[i-1][j-1];
      for(int i=0; i<=H_; i++) for(int j=1; j<=W_; j++) s[i][j] += s[i][j-1];
      for(int i=1; i<=H_; i++) for(int j=0; j<=W_; j++) s[i][j] += s[i-1][j];
    }

    // h : [i,j],  w : [k,m]
    long long Get(int i, int j, int k, int m) {
      return s[j+1][m+1] - s[i][m+1] + s[i][k] - s[j+1][k];
    }
};


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int H, W, K; std::cin >> H >> W >> K;

  CumulativeSum S(H, W);
  rep(i, H) {
    std::string s; std::cin >> s;
    rep(j, W) {
      int c = s[j]-'0';
      if ( c == 1 ) S.set(i,j,1);
    }
  }
  S.build();

  ll ans = 1e8;
  for(int x=0; x<(1LL<<(H)); x++) {
    std::vector<std::pair<int,int>> L;
    std::bitset<11> bs(x);
    int s = 0;
    for(int l=1; l<H; l++) {
      if (bs[l] != bs[l-1]) {
        L.push_back( {s, l-1} );
        s = l;
      }
    }
    L.push_back( {s,H-1} );

    int ys = 0;
    ll tmp = 0;
    for(int y=0; y<W; y++) {
      bool flag = false;
      for(int l=0; l<sz(L); l++) {
        if ( S.Get(L[l].first, L[l].second, ys, y) > K ) flag = true;
      }
      if ( flag ) {
        if ( ys == y ) {
          tmp = 1e9;
          break;
        }
        ys = y;
        tmp++;
      }
    }

    ans = std::min(ans, tmp+sz(L)-1);
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 384