import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val H, W, K = in.next().toInt
  val S = new Array[String](H+1)
  for (i <- 1 to H) {
    S(i) = "#" + in.next()
  }

  //
  var ans = Int.MaxValue
  for (_bit <- 1 to 1<<(H-1)) {
    breakable {
      var rowCnt = new Array[Int](H+1)
      var res = 0

      for (w <- 1 to H) {
        var bit = _bit

        val tmpRowCnt = new Array[Int](H+1)
        var row = 1

        for (h <- 1 to H) {
          if (S(h)(w) == '1')
            tmpRowCnt(row) += 1
        }

        if (bit % 2 == 1) {
          row += 1
        }

        var flag = false
        for (i <- 1 to H) {
          val now = tmpRowCnt(i)
          if (now > K)
            break()
          else {
            if (rowCnt(i) + tmpRowCnt(i) > K)
              flag = true
          }
        }

        if (flag) {
          res += 1
          rowCnt = tmpRowCnt
        }
        else {
          for (i <- 1 to H) {
            rowCnt(i) += tmpRowCnt(i)
          }
        }
      }

      ans = ans min (res + _bit.toBinaryString.count(_ == '1'))
    }
    
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.toList))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
