program dividing_chocolate
  implicit none
  integer :: h, w, k, a(10,1000) = 0, i, j, l, m, c(10), d(10), u, x = 1e9, y
  character(1000) :: s
  read(*,*) h, w, k
  do i = 1, h
    read(*,'(a)') s
    do j = 1, w
      if (s(j:j) == "1") a(i,j) = 1
    end do
  end do
  u = lshift(1,h-1)
  do l = 0, u-1
    c = 0
    d = 0
    y = popcnt(l)
    do j = 1, w
      m = 1
      do i = 1, h
        if (i /= 1 .and. btest(l,i-2)) m = m+1
        c(m) = c(m)+a(i,j)
      end do
      if (any(c > k)) then
        y = y+1
        c = c-d
        if (any(c > k)) goto 100
      end if
      d = c
    end do
    x = min(x,y)
100 end do
  write(*,'(i0)') x
end program dividing_chocolate