// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int h, w, k;
  cin.scan(h, w, k);
  string[] s = cin.nextArray!string(h);

  auto imos = new int[][](h, w);

  foreach (i; 0 .. h) {
    foreach (j; 0 .. w) {
      imos[i][j] = s[i][j] - '0';
    }
  }

  foreach (i; 0 .. h) {
    foreach (j; 1 .. w) {
      imos[i][j] += imos[i][j - 1];
    }
  }

  foreach (i; 1 .. h) {
    foreach (j; 0 .. w) {
      imos[i][j] += imos[i - 1][j];
    }
  }

  int res = int.max;

  foreach (bit; 0 .. 1 << (h - 1)) {
    int nowRes = 0;
    int[] div;
    foreach (i; 0 .. h - 1) {
      if (1 & (bit >> i)) {
        div ~= i;
      }
    }

    div ~= h - 1;
    nowRes += div.length - 1;

    // copy
    auto imosCopy = imos.dup;
    foreach (i; 0 .. h) {
      imosCopy[i] = imos[i].dup;
    }

    auto nowW = new int[w];
    foreach (i; div) {
      foreach (j; 0 .. w) {
        imosCopy[i][j] -= nowW[j];
        nowW[j] = imos[i][j];
      }
    }

    auto nowH = new int[h];
OUTER: foreach (j; 0 .. w) {
      bool over = false;
      foreach (i; div) {
        if (imosCopy[i][j] - nowH[i] > k) {
          over = true;
        }
      }

      if (over) {
        if (j == 0) {
          nowRes = int.max;
          break;
        }

        foreach (i; div) {
          nowH[i] = imos[i][j - 1];
          if (imos[i][j] - nowH[i] > k) {
            nowRes = int.max;
            break OUTER;
          }
        }
        nowRes++;

      }
    }

    res = min(res, nowRes);
  }

  writeln(res);

  /*
  foreach (i; 0 .. h) {
    foreach (j; 0 .. w) {
      writef("%s%s", imos[i][j], j == w - 1 ? "\n" : " ");
    }
  }
  */
}
