let popcnt x =
  let x = (x land 0x5555555555555555) + ((x lsr 1) land 0x5555555555555555) in
  let x = (x land 0x3333333333333333) + ((x lsr 2) land 0x3333333333333333) in
  let x = (x land 0x0f0f0f0f0f0f0f0f) + ((x lsr 4) land 0x0f0f0f0f0f0f0f0f) in
  let x = (x land 0x00ff00ff00ff00ff) + ((x lsr 8) land 0x00ff00ff00ff00ff) in
  let x = (x land 0x0000ffff0000ffff) + ((x lsr 16) land 0x0000ffff0000ffff) in
  (x land 0x00000000ffffffff) + ((x lsr 32) land 0x00000000ffffffff)

let () = Scanf.scanf "%d %d %d\n" @@ fun h w k ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let ops = ref 0 in
  let cursor = ref 0 in
  let blocks = Array.make h 0 in
  let current = Array.make h 0 in
  Printf.printf "%d\n" @@
  Array.fold_left min max_int @@
  Array.init (1 lsl (h - 1)) @@ fun bits ->
    try
      for i = 0 to h - 1 do
        blocks.(i) <- 0;
      done;
      ops := 0;
      for i = 0 to w - 1 do
        for i = 0 to h - 1 do
          current.(i) <- 0;
        done;
        cursor := 0;
        for j = 0 to h - 1 do
          if ss.(j).[i] = '1' then
            current.(!cursor) <- current.(!cursor) + 1;
          if 0 < bits land (1 lsl j) then incr cursor
        done;
        if
          Array.fold_left ( && ) true @@
          Array.init h @@ fun i -> blocks.(i) + current.(i) <= k
        then begin
          for i = 0 to h - 1 do
            blocks.(i) <- blocks.(i) + current.(i)
          done
        end else begin
          incr ops;
          for i = 0 to h - 1 do
            if k < current.(i) then raise Not_found;
            blocks.(i) <- current.(i)
          done
        end
      done;
      !ops + popcnt bits
    with Not_found -> max_int
