#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 998244353
#define INT_MAX1 900000000
#define MAXN 1000000
#define INF INT_MAX


string s[10];
int h, w, k;



int s1(vector<vi> q)
{
    int cc = 0;
    vector<int> tot(q.size(), 0);


    for(int j=0; j<w; j++)
    {   
        vi tot1 = tot;
        bool f = 1;
        rep(i,0,q.size()-1)
        {
            if(q[i][j]>k)
                return INT_MAX;
            tot1[i] += q[i][j];
            if(tot1[i]>k)
            {
                f = 0;
                break;
            }
        }
        if(!f)
        {
            j--;
            cc++;
            tot.clear();
            tot.resize(q.size(), 0);
            continue;
        }
        else
            tot = tot1;
    }
    return cc;
}


void solve()
{
   cin >> h >> w >> k;
   inp(s, h);


 int ans = INT_MAX;
   
   for(int i=1; i<(1<<h); i++)
   {

     int p = 0;
     vector<vi> q;
     rep(j,1,h-1)
     {


        if((i)&(1<<j))
        {
            int c = j-1;
            vi q1;
            for(int j1 = 0; j1<w; j1++)
            {
                int cc = 0;
                rep(k1, p, c)
                    cc += (s[k1][j1]=='1');
                q1.pb(cc);
            }
            q.pb(q1);
            p = j;
        }
     }


            int c = h-1;
            vi q1;
            for(int j1 = 0; j1<w; j1++)
            {
                int cc = 0;
                rep(k1, p, c)
                {
                    cc += (s[k1][j1]=='1');
                }
                q1.pb(cc);
            }

            
            q.pb(q1);
        ans = min(ans, s1(q)+(int)q.size()-1);
   }

   assert(ans!=INT_MAX);
   cout << ans << endl;

}

signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}


Measured memory_bytes: 492