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

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

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



As.sort()

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



iA = 0

for B, C in BCs:

    for j in range(B):

        if As[iA] < C:

            As[iA] = C

            iA += 1

            if iA >= N:

                break

        else:

            break

    else:

        continue

    break



print((sum(As)))

import sys

input = sys.stdin.readline



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

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

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



As.sort()

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



i = 0

for B, C in BCs:

    num = min(N-i, B)

    for j in range(i, i+num):

        if As[j] >= C:

            break

        As[j] = C

    else:

        i += B

        if i >= N:

            break

        continue

    break

#print('As:', As)



print((sum(As)))

N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(key=lambda x: x[1], reverse=True)
iA = 0
for B, C in BCs:
    for j in range(B):
        if As[iA] < C:
            As[iA] = C
            iA += 1
            if iA >= N:
                break
        else:
            break
    else:
        continue
    break
print((sum(As)))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(reverse=True, key=lambda x: x[1])
i = 0
for B, C in BCs:
    num = min(N - i, B)
    for j in range(i, i + num):
        if As[j] >= C:
            break
        As[j] = C
    else:
        i += B
        if i >= N:
            break
        continue
    break
# print('As:', As)
print((sum(As)))

+import sys + +input = sys.stdin.readline -BCs.sort(key=lambda x: x[1], reverse=True) -iA = 0 +BCs.sort(reverse=True, key=lambda x: x[1]) +i = 0 -    for j in range(B): -        if As[iA] < C: -            As[iA] = C -            iA += 1 -            if iA >= N: -                break -        else: +    num = min(N - i, B) +    for j in range(i, i + num): +        if As[j] >= C: +        As[j] = C +        i += B +        if i >= N: +            break +# print('As:', As)