program main
  implicit none
  integer :: h, w, k, i, j, t, ptr, res
  character(1000) :: s(10)
  integer, allocatable :: si(:, :), rows(:, :)
  read *, h, w, k
  allocate (si(w, h), rows(w, h))
  do i = 1, h
    read *, s(i)
    do j = 1, w
      read (s(i)(j:j), *) si(j, i)
    end do
  end do

  res = 10 ** 9
  do t = 0, 2 ** (h - 1) - 1  ! それぞれの鉛直分割法を全探索
    rows = 0
    ptr = 1
    do i = 1, h
      rows(:, ptr) = rows(:, ptr) + si(:, i)
      if (btest(t, i - 1)) then  ! iの後ろで分割される
        ptr = ptr + 1
      end if
    end do

    ! rowsのh行のうちptr行が使われた
    res = min(res, hdiv(rows, w, h, k) + ptr - 1)
  end do

  print "(i0)", res

  contains

  integer function hdiv(rows, w, h, k)
    ! Greedyに最小限の水平分割する
    integer, intent(in) :: w, h, k
    integer, intent(in) :: rows(w, h)
    integer :: cnt(h), j
    if (maxval(rows) > k) then
      hdiv = 10 ** 9
      return
    end if
    hdiv = 0
    cnt = 0
    do j = 1, w
      cnt(:) = cnt(:) + rows(j, :)
      if (maxval(cnt) > k) then
        hdiv = hdiv + 1
        cnt(:) = rows(j, :)
      end if
    end do
  end function hdiv
end program main
