program main
    implicit none
    integer(8) n,m,k
    integer(8), allocatable, dimension(:) :: a, b
    integer(8) i, time, na, nb, c

    read(*,*) n,m,k
    allocate(a(n))
    read(*,*) a
    allocate(b(m))
    read(*,*) b

    time = k
    c = 0

    na = 1
    nb = 1
    do i = 1,n+m
        if(a(na) < b(nb)) then
            time = time - a(na)
            na = na + 1
        else if(a(na) > b(nb)) then
            time = time - b(nb)
            nb = nb + 1
        else if(a(na) == b(nb)) then
            if(a(na+1) < b(nb+1)) then
                time = time - a(na)
                na = na + 1
            else if(a(na+1) > b(nb+1)) then
                time = time - b(nb)
                nb = nb + 1
            else if(a(na+1) == b(nb+1)) then
                time = time - a(na)
                na = na + 1
            end if
        end if
        if(time < 0) then
            exit
        end if
        c = c + 1
    end do
    write(*,*) c

end program
