#include <bits/stdc++.h>

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define lwb             lower_bound
#define upb             upper_bound
#define all(a)          (a).begin(), (a).end()
#define Reset(s, n)     memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define bit(n, i)       (((n) >> (i)) & 1)
#define cntbit(n)       __builtin_popcountll(ll(n))

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const ll INF = 1e9;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline bool isPrime (ll x){ if(x <= 1) return 0; if(x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ll s = sqrt(1.0 * x) + EPS; for(ll i = 5; i <= s; i += 6){if (!(x % i) || !(x % (i + 2))) return 0;}return 1;}
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, ll p = MOD) {return fpow(a, p - 2, p);}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline void onbit(ll &a, int i){a |= 1LL << i;}
inline void offbit(ll &a, int i){onbit(a, i), a -= (1LL << i);}

const int N = 3e5 + 5;


ll n, m, k;
bitset<1005> a[11];

void solve(){
   cin >> m >> n >> k;
   for(int i = 0; i < m; i++){
      for(int j = 0; j < n; j++){
         char x;
         cin >> x;
         a[i][j] = x - 48;
      }
   }
   if(m == 1){
      int res = 0;
      for(int i = 0; i < n; i++){
         res += a[0][i];
      }
      cout << (res + (k - 1)) / k;
      return;
   }
   int ans = 2e9;
   for(int mask = 0; mask < (1 << (m - 1)); mask++){
      GOTO:
//      if(mask != 5) continue;
      vector<int> white(1005, 0);
      int res = 0;
      for(int j = 0; j < n; j++){
         int cnt = 0;
         bool ok = 1;
         for(int i = 0; i < m; i++){
            white[cnt] += a[i][j];
            if(white[cnt] > k){
               ok = 0;
            }
            if(bit(mask, i)){
               cnt++;
            }
         }
         cnt = 0;
         if(!ok){
            res++;
            white.assign(1005, 0);
            for(int i = 0; i < m; i++){
               white[cnt] += a[i][j];
               if(white[cnt] > k){
                  mask++;
                  goto GOTO;
               }
               if(bit(mask, i)){
                  cnt++;
               }
            }
         }
//         cout << j << " " << res << "\n";
//         for(int i = 0; i < 9; i++) cout << white[i] << " "; cout << "\n";
      }
      ans = min(ans, res + cntbit(mask));
   }
   if(ans > 1e9){
      cout << 0;
      return;
   }
   cout << ans << "\n";
}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(10);
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   int query = 1;
//   cin >> query;
   int start = 1000 * clock() / CLOCKS_PER_SEC;
   while(query--) solve();
   cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


Measured memory_bytes: 256