import heapq

N,M=list(map(int,input().split()))

A = list(map(int,input().split()))

heapq.heapify(A)

l = [] 

for i in range(M):

  tmp = list(map(int,input().split()))

  l.append([tmp[1],tmp[0]])

l.sort(reverse=True)





for i,j in l:

  for I in range(j):

    Q = heapq.heappop(A)

    if Q<i :

      heapq.heappush(A,i)

    else:

      heapq.heappush(A,Q)

      break

# print(A)

print((sum(A)))
N,M=list(map(int,input().split()))

A = list(map(int,input().split()))

l = [] 

for i in range(M):

  tmp = list(map(int,input().split()))

  l.append([tmp[1],tmp[0]])

l.sort(reverse=True)

for i,j in l:

    A.extend([i]*j)

    if len(A)>2*N:break

A.sort(reverse=True)

print((sum(A[:N])))
import heapq

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
l = []
for i in range(M):
    tmp = list(map(int, input().split()))
    l.append([tmp[1], tmp[0]])
l.sort(reverse=True)
for i, j in l:
    for I in range(j):
        Q = heapq.heappop(A)
        if Q < i:
            heapq.heappush(A, i)
        else:
            heapq.heappush(A, Q)
            break
# print(A)
print((sum(A)))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
l = []
for i in range(M):
    tmp = list(map(int, input().split()))
    l.append([tmp[1], tmp[0]])
l.sort(reverse=True)
for i, j in l:
    A.extend([i] * j)
    if len(A) > 2 * N:
        break
A.sort(reverse=True)
print((sum(A[:N])))

-import heapq - -heapq.heapify(A) -    for I in range(j): -        Q = heapq.heappop(A) -        if Q < i: -            heapq.heappush(A, i) -        else: -            heapq.heappush(A, Q) -            break -# print(A) -print((sum(A))) +    A.extend([i] * j) +    if len(A) > 2 * N: +        break +A.sort(reverse=True) +print((sum(A[:N])))