program main
Implicit None
	integer(8)::n,m,i,u,j
	integer(8),allocatable::a(:),b(:),c(:),t(:)
	
	read*,n,m
	allocate(a(n),b(m),c(m),t(n))
	
	read*,a
	call h1(a,n)
	
	do i =1,m
		read*,b(i),c(i)
	enddo
	
	call h2(c,b,m)
	u = m
	
	do i = 1,n
		if(a(i) < c(u))then
			a(i) = c(u)
			b(u) = b(u)-1
			if(b(u) == 0) u = u-1
			if(u == 0)exit
		endif
	enddo
	
	print"(i0)",sum(a)
end program main
 
subroutine schint(a,n,x,p)
implicit None
	integer(8)::n,s,e,x,p,t,i
	integer(8)::a(n)
	
	s =1;e =n
	do
		if(e-s < 3)then
			do i = s,e
				if(a(i) >= x)then
				p = i-1
				return
				endif
			enddo
		endif
		
		t = (s+e)/2
		if(a(t) > x)then
			e = t
			else
			s = t
		endif
	enddo
end subroutine schint

subroutine h2(a,b,n)
implicit None
	integer(8)::a(n),b(n),x,y
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie)
		a(ie) = a(1);b(ie) = b(1)
		a(1) = x;b(1) = y
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2

 
subroutine h1(a,n)
implicit None
	integer(8)::a(n),x
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie)
		a(ie) = a(1)
		a(1) = x
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h1
