      PROGRAM DividingChocolate
      IMPLICIT NONE
      integer :: h,w,k
      integer,allocatable :: choco(:,:)
      integer,allocatable :: memo1(:),memo2(:),counter2(:),this(:)
      character(1000) :: s
      integer :: i,j,buffer,piyo
      
      
      read*,h,w,k
      allocate( choco(h,w),memo1(h-1),memo2(w-1) )
      choco = 0
      memo1 = 0
      memo2 = 0
      do i = 1,h
        read*,s
        do j = 1,w
          if( s(j:j)=='1' )then
            choco(i,j) = 1
          end if
        end do
      end do
      
      !tate
      buffer = sum( choco(1,:) )
      do i = 2,h
        if( buffer+sum(choco(i,:))>k )then
          buffer = sum( choco(i,:) )
          memo1(i-1) = 1
        end if
      end do
      
      
      
      !yoko
      allocate( counter2(sum(memo1)),this(sum(memo1)) )
      counter2 = 0
      piyo = 1
      do i = 1,h
        counter2(piyo) = counter2(piyo) + choco(i,1)
        if(memo1(i)==1) piyo = piyo + 1
      end do
      this = 0
      do j = 2,w
        piyo = 1
        
        do i = 1,h
          this(piyo) = this(piyo) + choco(i,j)
          
          if(memo1(i)==1)then
            piyo = piyo + 1
          end if
        end do
        
        if( maxval(counter2+this)>k )then
          counter2 = this
          memo2(j-1) = 1
        end if
      end do
      
      print*,sum(memo1) + sum(memo2)
      
      
      !debugg
    !  print*,trim(s)
    !  do i = 1,h
    !    print*,choco(i,:)
    !  end do
    !  
    !  print*,memo1
    !  print*,memo2
      
      END PROGRAM