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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
template <class T>
void show(vector<T> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i] << " ";
    }
    cerr << "\n";
}
typedef long long ll;

int grid[15][1010];
int rui[1010][15];
signed main()
{
    int h,w,k;
    cin>>h>>w>>k;
    vector<string>s(h);
    REP(i,h) cin>>s[i];
   REP(i,h) {
       REP(j,w) {
            grid[i][j] = s[i][j]-'0';
       }
   }
   //cerr<<"a";

   
   
    for (int i = 0; i < w; i++)
    {
        rui[i][0]=0;
        for (int j = 1; j <= h; j++)
        {
            rui[i][j]=rui[i][j-1]+grid[j-1][i];
        }
    }

    int ans=INF;
    for(int bit=0;bit < (1<< (h-1) );bit++){
        int tmp=0;
        int loc=0;
        string s;
       bool ok = true;
       int copy_bit =bit + (1<<(h-1));
       vector<int>v;
       v.push_back(0);
       REP(i,h) {
           if ((1 << i) & copy_bit)
                {
                    v.push_back(i+1);
                }
        }
        vector<int>cnt(v.size(),0);
      //  show(v);
        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < v.size()-1; j++)
            {
                if (rui[i][v[j + 1]] - rui[i][v[j]] > k) ok=false;
                    cnt[j] += rui[i][v[j + 1]] - rui[i][v[j]];
                //   show(cnt);
                if(cnt[j] > k ) {
                    tmp++;
                    for (int l = 0; l < v.size() - 1; l++){
                        cnt[l] = rui[i][v[l + 1] ] - rui[i][v[l]];
                    }
                    break;
                }
            }
            
        }
        
       
       
      //  cerr<<"tmp="<<tmp<<endl;
      if(ok)  chmin(ans,tmp - 2LL + (ll)v.size());
        
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512