#include "bits/stdc++.h"
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q, m, K, ans = INF;
char mat[20][1008];
int  val[20][1008];


void solve()
{     
      cin >> n >> m >>K;
      lop(i,1,n+1)lop(j,1,m+1) cin >> mat[i][j];

      lop(j,1,m+1)
      {
            lop(i,1,n+1)
            {
                  val[i][j] = val[i-1][j] + (mat[i][j] == '1');
            }
      }


      lop(i,0,(1<<n))
      {     

            vector<int> vec;
            int res = 0;
            lop(j,0,n-1)
            {
                  if( i&(1<<j) )
                  {
                        vec.pb(j+1);
                        res++;
                  }
            }
            vec.pb(n);

            
            int j = 1, sz = vec.size(), total[sz];
                        memset(total, 0, sizeof total);

            
            int st = 1, pos = 1;
            while( j<=m )
            {     
                  int p = 0, f = 1;
                  for(int k = 0; k < sz; k++)
                  {
                        total[k] += (val[ vec[k] ][j] - val[p][j]);
                        if(total[k] > K) f = 0;
                        p = vec[k];
                  }

                  if(f) j++;
                  else
                  {     
                        if(st == j)
                        {
                              pos = 0;
                              break;
                        }
                        else st = j;
                        res++;
                        memset(total, 0, sizeof total);
                  }
            }


            if(pos)ans = min(ans, res);
      }

      cout << ans;
      
}


int32_t main()
{
      
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
     // INP(); 
      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 384