from heapq import *





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

PAIRS = [[-a, -1] for a in map(int, input().split())]

heapify(PAIRS)



for _ in range(m):

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

    heappush(PAIRS, [-c, -b])



answer = 0

for _ in range(n):

    pair = heappop(PAIRS)

    answer += -pair[0]

    pair[1] += 1

    if pair[1] != 0:

        heappush(PAIRS, pair)



print(answer)

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

PAIRS = [(a, 1) for a in map(int, input().split())]



for _ in range(m):

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

    PAIRS.append((c, b))

PAIRS.sort(reverse = True)



answer, count = 0, 0

for pair in PAIRS:

    answer += pair[0] * pair[1]

    count += pair[1]

    if count > n:

        answer -= pair[0] * (count - n)

        break



print(answer)

from heapq import *

n, m = list(map(int, input().split()))
PAIRS = [[-a, -1] for a in map(int, input().split())]
heapify(PAIRS)
for _ in range(m):
    b, c = list(map(int, input().split()))
    heappush(PAIRS, [-c, -b])
answer = 0
for _ in range(n):
    pair = heappop(PAIRS)
    answer += -pair[0]
    pair[1] += 1
    if pair[1] != 0:
        heappush(PAIRS, pair)
print(answer)

n, m = list(map(int, input().split()))
PAIRS = [(a, 1) for a in map(int, input().split())]
for _ in range(m):
    b, c = list(map(int, input().split()))
    PAIRS.append((c, b))
PAIRS.sort(reverse=True)
answer, count = 0, 0
for pair in PAIRS:
    answer += pair[0] * pair[1]
    count += pair[1]
    if count > n:
        answer -= pair[0] * (count - n)
        break
print(answer)

-from heapq import * - -PAIRS = [[-a, -1] for a in map(int, input().split())] -heapify(PAIRS) +PAIRS = [(a, 1) for a in map(int, input().split())] -    heappush(PAIRS, [-c, -b]) -answer = 0 -for _ in range(n): -    pair = heappop(PAIRS) -    answer += -pair[0] -    pair[1] += 1 -    if pair[1] != 0: -        heappush(PAIRS, pair) +    PAIRS.append((c, b)) +PAIRS.sort(reverse=True) +answer, count = 0, 0 +for pair in PAIRS: +    answer += pair[0] * pair[1] +    count += pair[1] +    if count > n: +        answer -= pair[0] * (count - n) +        break