from heapq import heapify, heappush, heappop



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

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

hq = list([(-x, 1) for x in a])



heapify(hq)



for _ in range(M):

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

    heappush(hq, (-c, b))



rest = N

ans = 0

while rest > 0 and hq:

    mv, b = heappop(hq)

    mv *= -1

    use = min(rest, b)

    ans += mv * use

    rest -= use

print(ans)

from heapq import heappop, heappush



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

a = tuple(map(int, input().split()))



hq = []

for aa in a:

    heappush(hq, (-aa, 1))



for _ in range(m):

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

    heappush(hq, (-c, b))



rest = n

ans = 0

while rest > 0:

    num, cnt = heappop(hq)



    num *= (-1)

    use = min(rest, cnt)

    ans += use * num

    rest -= use



print(ans)

from heapq import heapify, heappush, heappop

N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
hq = list([(-x, 1) for x in a])
heapify(hq)
for _ in range(M):
    b, c = list(map(int, input().split()))
    heappush(hq, (-c, b))
rest = N
ans = 0
while rest > 0 and hq:
    mv, b = heappop(hq)
    mv *= -1
    use = min(rest, b)
    ans += mv * use
    rest -= use
print(ans)

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
a = tuple(map(int, input().split()))
hq = []
for aa in a:
    heappush(hq, (-aa, 1))
for _ in range(m):
    b, c = list(map(int, input().split()))
    heappush(hq, (-c, b))
rest = n
ans = 0
while rest > 0:
    num, cnt = heappop(hq)
    num *= -1
    use = min(rest, cnt)
    ans += use * num
    rest -= use
print(ans)

-from heapq import heapify, heappush, heappop +from heapq import heappop, heappush -N, M = list(map(int, input().split())) -a = list(map(int, input().split())) -hq = list([(-x, 1) for x in a]) -heapify(hq) -for _ in range(M): +n, m = list(map(int, input().split())) +a = tuple(map(int, input().split())) +hq = [] +for aa in a: +    heappush(hq, (-aa, 1)) +for _ in range(m): -rest = N +rest = n -while rest > 0 and hq: -    mv, b = heappop(hq) -    mv *= -1 -    use = min(rest, b) -    ans += mv * use +while rest > 0: +    num, cnt = heappop(hq) +    num *= -1 +    use = min(rest, cnt) +    ans += use * num