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

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

BC = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)



ans = 0

j = 0

for b, c in BC:

    for i in range(b):

        if j < n:

            ans += max(c, A[j])

            j += 1

        else:

            break



if j < n:

    for i in range(n - j):

        ans += A[n - 1 - i]



print(ans)

import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

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

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

    query = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1], reverse=True)



    B = []

    for i in range(m):

        b, c = query[i]

        while b and len(B) != n:

            B.append(c)

            b -= 1

    B.sort(reverse=True)



    for i in range(len(B)):

        if A[i] < B[i]:

            A[i] = B[i]

    print((sum(A)))





if __name__ == '__main__':

    resolve()

n, m = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
BC = sorted(
    [list(map(int, input().split())) for _ in range(m)],
    key=lambda x: x[1],
    reverse=True,
)
ans = 0
j = 0
for b, c in BC:
    for i in range(b):
        if j < n:
            ans += max(c, A[j])
            j += 1
        else:
            break
if j < n:
    for i in range(n - j):
        ans += A[n - 1 - i]
print(ans)

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    n, m = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    query = sorted(
        [list(map(int, input().split())) for _ in range(m)],
        key=lambda x: x[1],
        reverse=True,
    )
    B = []
    for i in range(m):
        b, c = query[i]
        while b and len(B) != n:
            B.append(c)
            b -= 1
    B.sort(reverse=True)
    for i in range(len(B)):
        if A[i] < B[i]:
            A[i] = B[i]
    print((sum(A)))


if __name__ == "__main__":
    resolve()

-n, m = list(map(int, input().split())) -A = sorted(list(map(int, input().split()))) -BC = sorted( -    [list(map(int, input().split())) for _ in range(m)], -    key=lambda x: x[1], -    reverse=True, -) -ans = 0 -j = 0 -for b, c in BC: -    for i in range(b): -        if j < n: -            ans += max(c, A[j]) -            j += 1 -        else: -            break -if j < n: -    for i in range(n - j): -        ans += A[n - 1 - i] -print(ans) +import sys + +sys.setrecursionlimit(10**7) +input = sys.stdin.readline +f_inf = float("inf") +mod = 10**9 + 7 + + +def resolve(): +    n, m = list(map(int, input().split())) +    A = sorted(list(map(int, input().split()))) +    query = sorted( +        [list(map(int, input().split())) for _ in range(m)], +        key=lambda x: x[1], +        reverse=True, +    ) +    B = [] +    for i in range(m): +        b, c = query[i] +        while b and len(B) != n: +            B.append(c) +            b -= 1 +    B.sort(reverse=True) +    for i in range(len(B)): +        if A[i] < B[i]: +            A[i] = B[i] +    print((sum(A))) + + +if __name__ == "__main__": +    resolve()