program kadai
implicit none

integer  ::  n,m,i,j
integer(16)  ::  ans
integer,allocatable  ::  A(:)
integer,allocatable  ::  B(:)
integer(8),allocatable  ::  C(:)

read(*,*) n,m

allocate(A(n))
allocate(B(m))
allocate(C(m))

read(*,*) A
do i=1,m
    read(*,*) B(i),C(i)
end do

do i=1,m
    do j=1,B(i)
        if(minval(A)==C(i) .or. minval(A)>C(i)) then
            exit
        end if
        if(minval(A)<C(i)) then
            A(minloc(A,minval(A)))=C(i)
        end if
    end do

end do
ans=0
do i=1,n
ans=ans+A(i)
end do
write(*,*) ans


end program kadai