import heapq

n, m = list(map(int, input().split()))

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

bc_lst = [list(map(int, input().split())) for _ in range(m)]



bc_lst = sorted(bc_lst, key = lambda x: -x[1])

aa_lst = a_lst[:]



heapq.heapify(aa_lst)

for bc in bc_lst:

    for i in range(bc[0]):

        if aa_lst[0] < bc[1]:

            heapq.heapreplace(aa_lst, bc[1])

        else:

            break

        

print((sum(aa_lst)))
n, m = list(map(int, input().split()))

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

bc_lst = [list(map(int, input().split())) for _ in range(m)]



sorted_a = sorted(a_lst)

sorted_bc = sorted(bc_lst, key = lambda x: -x[1])



bc_index = 0

bc_count = 1

bc = sorted_bc[bc_index]

for i in range(n):

    if sorted_a[i] < bc[1]:

        sorted_a[i] = bc[1]

    else:

        break

    if bc[0] == bc_count:

        bc_count = 1

        bc_index += 1

        if len(sorted_bc) == bc_index:

            break

        else:

            bc = sorted_bc[bc_index]

    else:

        bc_count += 1

print((sum(sorted_a)))
import heapq

n, m = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]
bc_lst = sorted(bc_lst, key=lambda x: -x[1])
aa_lst = a_lst[:]
heapq.heapify(aa_lst)
for bc in bc_lst:
    for i in range(bc[0]):
        if aa_lst[0] < bc[1]:
            heapq.heapreplace(aa_lst, bc[1])
        else:
            break
print((sum(aa_lst)))

n, m = list(map(int, input().split()))
a_lst = list(map(int, input().split()))
bc_lst = [list(map(int, input().split())) for _ in range(m)]
sorted_a = sorted(a_lst)
sorted_bc = sorted(bc_lst, key=lambda x: -x[1])
bc_index = 0
bc_count = 1
bc = sorted_bc[bc_index]
for i in range(n):
    if sorted_a[i] < bc[1]:
        sorted_a[i] = bc[1]
    else:
        break
    if bc[0] == bc_count:
        bc_count = 1
        bc_index += 1
        if len(sorted_bc) == bc_index:
            break
        else:
            bc = sorted_bc[bc_index]
    else:
        bc_count += 1
print((sum(sorted_a)))

-import heapq - -bc_lst = sorted(bc_lst, key=lambda x: -x[1]) -aa_lst = a_lst[:] -heapq.heapify(aa_lst) -for bc in bc_lst: -    for i in range(bc[0]): -        if aa_lst[0] < bc[1]: -            heapq.heapreplace(aa_lst, bc[1]) +sorted_a = sorted(a_lst) +sorted_bc = sorted(bc_lst, key=lambda x: -x[1]) +bc_index = 0 +bc_count = 1 +bc = sorted_bc[bc_index] +for i in range(n): +    if sorted_a[i] < bc[1]: +        sorted_a[i] = bc[1] +    else: +        break +    if bc[0] == bc_count: +        bc_count = 1 +        bc_index += 1 +        if len(sorted_bc) == bc_index: +            break -            break -print((sum(aa_lst))) +            bc = sorted_bc[bc_index] +    else: +        bc_count += 1 +print((sum(sorted_a)))