#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
char a[15][1005];
ll h,w,k,b[15][1005],ans=INF,preh,prew,cnt,flag,maxn;
int main()
{
    //IOS;
    cin>>h>>w>>k;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+(a[i][j]-'0');
        }
    }
    for(int i=0; i<(1<<(h-1)); i++)
    {
        flag=0;
        prew=0;
        cnt=0;
        for(int k=1; k<=h-1; k++)
        {
            if((i&(1<<(k-1)))!=0)
            {
                cnt++;
            }
        }
        //cout<<cnt<<endl;
        for(int j=1; j<=w; j++)
        {
            preh=0;
            maxn=0;
            for(int k=1; k<=h-1; k++)
            {
                if((i&(1<<(k-1)))!=0)
                {
                    //cout<<preh<<endl;
                    maxn=max(maxn,b[k][j]-b[preh][j]-b[k][prew]+b[preh][prew]);
                    preh=k;
                }
            }
            maxn=max(maxn,b[h][j]-b[preh][j]-b[h][prew]+b[preh][prew]);
            if(maxn>k)
            {
                if(j-prew==1)
                {
                    flag=1;
                    break;
                }
                else
                {
                    //cout<<preh<<' '<<j-1<<endl;
                    cnt++;
                    prew=j-1;
                }
            }
        }
        preh=0;
        maxn=0;
        for(int k=1; k<=h-1; k++)
        {
            if((i&(1<<(k-1)))!=0)
            {
                maxn=max(maxn,b[k][w]-b[preh][w]-b[k][prew]+b[preh][prew]);
                preh=k;
            }
        }
        maxn=max(maxn,b[h][w]-b[preh][w]-b[h][prew]+b[preh][prew]);
        if(maxn>k)
        {
            if(w-prew==1)
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            //cout<<i<<' '<<cnt<<endl;
            ans=min(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 384