program k3
	implicit none
    integer :: n, m, k, i, j, f, g
    integer :: l(3)
    integer, allocatable :: a(:), b(:)
    
    read(*,*) l
    n = l(1)
    m = l(2)
    k = l(3)
    allocate(a(n))
    allocate(b(m))
    read(*,*) a
    read(*,*) b
    f = 0
    j = 0
    do g = 1, n+m
    	if (a(1) <= b(1) .and. a(1) /= 0) then
        	f = f + a(1)
            if (k < f) then
                exit
            end if            
            do i = 2, n
            	a(i-1) = a(i)
            enddo
            a(n) = 0           
       	else if (b(1) < a(1) .and. b(1) /= 0) then
         	f = f + b(1)
            if (k < f) then
                exit
            end if 
            do i = 2, m
            	b(i-1) = b(i)
            enddo 
            b(m) = 0
        else if (a(1) == 0 .and. b(1) == 0) then
        	exit
        else if (a(1) == 0 .and. b(1) /= 0) then
	        f = f + b(1)
            if (k < f) then
                exit
            end if 
            do i = 2, m
            	b(i-1) = b(i)
            enddo 
            b(m) = 0 
        else if (b(1) == 0 .and. a(1) /= 0) then
        	f = f + a(1)
            if (k < f) then
                exit
            end if            
            do i = 2, n
            	a(i-1) = a(i)
            enddo
            a(n) = 0               	
    	end if
		j = j + 1
    end do
   	write(*,*) j
end program k3