import copy

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

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

A.sort()

A_copy = copy.deepcopy(A)

CB = []

for i in range(M):

    b,c = list(map(int,input().split()))

    CB.append([c,b])

CB.sort(reverse = True)

tmp = 0

for c,b in CB:

    for i in range(b):

        if tmp+i >= N:

            print((sum(A)))

            exit()

            

        if A_copy[tmp+i]<c:

            A[tmp+i] = c

        else:

            break

    tmp += b

print((sum(A)))

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

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

A.sort()

CB = []

for i in range(m):

   b,c = list(map(int,input().split()))

   CB.append([c,b])

CB.sort(reverse=True)

ans = sum(A)

index = 0

for c,b in CB:

    for i in range(b):

        if index >=n:

            print(ans)

            exit()

        if A[index] < c:

            ans += c-A[index]

            A[index] = c

            index += 1

        else:

            print(ans)

            exit()

print(ans)



import copy

N, M = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
A_copy = copy.deepcopy(A)
CB = []
for i in range(M):
    b, c = list(map(int, input().split()))
    CB.append([c, b])
CB.sort(reverse=True)
tmp = 0
for c, b in CB:
    for i in range(b):
        if tmp + i >= N:
            print((sum(A)))
            exit()
        if A_copy[tmp + i] < c:
            A[tmp + i] = c
        else:
            break
    tmp += b
print((sum(A)))

n, m = list(map(int, input().split()))
A = [int(i) for i in input().split()]
A.sort()
CB = []
for i in range(m):
    b, c = list(map(int, input().split()))
    CB.append([c, b])
CB.sort(reverse=True)
ans = sum(A)
index = 0
for c, b in CB:
    for i in range(b):
        if index >= n:
            print(ans)
            exit()
        if A[index] < c:
            ans += c - A[index]
            A[index] = c
            index += 1
        else:
            print(ans)
            exit()
print(ans)

-import copy - -N, M = list(map(int, input().split())) +n, m = list(map(int, input().split())) -A_copy = copy.deepcopy(A) -for i in range(M): +for i in range(m): -tmp = 0 +ans = sum(A) +index = 0 -        if tmp + i >= N: -            print((sum(A))) +        if index >= n: +            print(ans) -        if A_copy[tmp + i] < c: -            A[tmp + i] = c +        if A[index] < c: +            ans += c - A[index] +            A[index] = c +            index += 1 -            break -    tmp += b -print((sum(A))) +            print(ans) +            exit() +print(ans)