program main
  implicit none
  type pair
    integer(8) :: b, c
  end type pair
  integer(8) :: n, m, i, j, k
  integer(8), allocatable :: a(:), sub(:)
  type(pair), allocatable :: pairs(:)
  read (*, *) n, m
  allocate (a(n), pairs(m), sub(n))
  read (*, *) a(:)
  do i = 1, m
    read *, pairs(i)%b, pairs(i)%c
  end do

  call quicksort(a)
  call quicksort2(pairs)
  j = 1
  outer: do i = m, 1, -1
    do k = 1, pairs(i)%b
      sub(j) = pairs(i)%c
      j = j + 1
      if (j > n) exit outer
    end do
  end do outer

  do i = 1, n
    a(i) = max(a(i), sub(i))
  end do

  print "(i0)", sum(a)
  contains

  recursive subroutine quicksort(a)
    integer(8), intent(inout) :: a(:)
    integer(8) :: pivot, i, j, k, tmp, n
    real(4) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot <= a(i))
        i = i + 1
      end do
      do while (.not. a(j) <= pivot)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort(a(1:i - 1))
    call quicksort(a(j + 1:n))
  end subroutine quicksort

  recursive subroutine quicksort2(a)
    type(pair), intent(inout) :: a(:)
    type(pair) :: pivot, tmp
    integer :: i, j, k, n
    real(4) :: r
    n = size(a)
    if (n <= 1) return
    i = 1
    j = n
    call random_number(r)
    k = 1 + floor(r * n)
    k = max(1, min(k, n))
    pivot = a(k)
    do
      do while (.not. pivot%c <= a(i)%c)
        i = i + 1
      end do
      do while (.not. a(j)%c <= pivot%c)
        j = j - 1
      end do
      if (i >= j) exit
      tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
      i = i + 1
      j = j - 1
    end do
    call quicksort2(a(1:i - 1))
    call quicksort2(a(j + 1:n))
  end subroutine quicksort2
end program main
