integer(16),allocatable,dimension(:)::A
integer(16),allocatable,dimension(:)::B
integer(16),allocatable,dimension(:)::C
integer(16) N,M
integer cindex
read*,N,M
allocate(A(N),B(M),C(M))
read*,A
call heapsort(N,A)
do i=1,M
  read*,B(i),C(i)
end do
call insertionsort(C,B)
cindex=1
do i=1,N
  if(C(cindex)>A(i))then
    A(i)=C(cindex)
    B(cindex)=B(cindex)-1
    if(B(cindex)==0)cindex=cindex+1
    if(cindex>M)exit
  else
    exit
  endif
end do
print"(I0)",sum(A)

contains
subroutine insertionsort(s,b)
  implicit none
  integer(16), intent(inout) :: s(:),b(:)
  integer(16) :: i, j, tmp
  do i = 2, size(s)  ! ループ終了時に [1, i] の範囲が昇順
    do j = i, 2, -1  ! i の位置にあった新要素が適切な位置に来るまで落ちてくる
      if (s(j) <= s(j - 1)) exit
      tmp = s(j)
      s(j) = s(j - 1)
      s(j - 1) = tmp
      tmp=b(j)
      b(j)=b(j-1)
      b(j-1)=tmp
    end do
  end do
end subroutine insertionsort


subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end