import sys

sys.setrecursionlimit(1000000)



from collections import defaultdict



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

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



dict = defaultdict(int)



for i in range(M):

  B, C = list(map(int, input().split()))

  dict[C] += B



idx = 0

for k, v in sorted(list(dict.items()), key=lambda x: -x[0]):

  for _ in range(v):

    if idx+1 <= len(A):

      if A[idx] < k:

      	A[idx] = k

      	idx += 1

      else:

        print((sum(A)))

        exit()

    else:

      print((sum(A)))

      exit()

      

      

print((sum(A)))

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

A = sorted([int(i) for i in input().split()])

BC = [tuple(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)



ans = 0

j = 0

b = 0

for i in range(N):

    if j < M and A[i] < BC[j][1]:

        ans += BC[j][1]

        b += 1

        if b == BC[j][0]:

            j += 1

            b = 0

    else:

        ans += A[i]

print(ans)

import sys

sys.setrecursionlimit(1000000)
from collections import defaultdict

N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
dict = defaultdict(int)
for i in range(M):
    B, C = list(map(int, input().split()))
    dict[C] += B
idx = 0
for k, v in sorted(list(dict.items()), key=lambda x: -x[0]):
    for _ in range(v):
        if idx + 1 <= len(A):
            if A[idx] < k:
                A[idx] = k
                idx += 1
            else:
                print((sum(A)))
                exit()
        else:
            print((sum(A)))
            exit()
print((sum(A)))

N, M = list(map(int, input().split()))
A = sorted([int(i) for i in input().split()])
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
ans = 0
j = 0
b = 0
for i in range(N):
    if j < M and A[i] < BC[j][1]:
        ans += BC[j][1]
        b += 1
        if b == BC[j][0]:
            j += 1
            b = 0
    else:
        ans += A[i]
print(ans)

-import sys - -sys.setrecursionlimit(1000000) -from collections import defaultdict - -A = sorted(list(map(int, input().split()))) -dict = defaultdict(int) -for i in range(M): -    B, C = list(map(int, input().split())) -    dict[C] += B -idx = 0 -for k, v in sorted(list(dict.items()), key=lambda x: -x[0]): -    for _ in range(v): -        if idx + 1 <= len(A): -            if A[idx] < k: -                A[idx] = k -                idx += 1 -            else: -                print((sum(A))) -                exit() -        else: -            print((sum(A))) -            exit() -print((sum(A))) +A = sorted([int(i) for i in input().split()]) +BC = [tuple(map(int, input().split())) for _ in range(M)] +BC.sort(key=lambda x: x[1], reverse=True) +ans = 0 +j = 0 +b = 0 +for i in range(N): +    if j < M and A[i] < BC[j][1]: +        ans += BC[j][1] +        b += 1 +        if b == BC[j][0]: +            j += 1 +            b = 0 +    else: +        ans += A[i] +print(ans)