program prob2
    implicit none
    integer::AA, BB, M, i, x, y, c, ans
    integer, allocatable::A(:), B(:)
    read(*,*) AA, BB, M
    allocate(A(AA))
    allocate(B(BB))
    read(*,*) A
    read(*,*) B

    ans = minval(A) + minval(B)
    do i = 1, M
        read(*,*) x, y, c
        if(ans > A(x) + B(y) - c) then
            ans = A(x) + B(y) - c
        end if
    end do

    write(*,*) ans

    deallocate(A)
    deallocate(B)

    stop

end program prob2