from collections import Counter

from heapq import heapify, heappop, heappush





class Data:

    def __init__(self, value, count):

        self.value = value

        self.count = count



    def __lt__(self, other):

        return self.value > other.value

    # 降順に取り出す





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

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



q = list()

heapify(q)

for v, c in list(Counter(a).items()):

    heappush(q, Data(v, c))



for _ in range(M):

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

    heappush(q, Data(v, c))



ans = 0

cnt = 0

while cnt < N:

    d = heappop(q)

    # print(d.value, d.count)

    chg = min(N - cnt, d.count)

    ans += chg * d.value

    cnt += chg



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 collections import Counter
from heapq import heapify, heappop, heappush


class Data:
    def __init__(self, value, count):
        self.value = value
        self.count = count

    def __lt__(self, other):
        return self.value > other.value

    # 降順に取り出す


N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
q = list()
heapify(q)
for v, c in list(Counter(a).items()):
    heappush(q, Data(v, c))
for _ in range(M):
    c, v = list(map(int, input().split()))
    heappush(q, Data(v, c))
ans = 0
cnt = 0
while cnt < N:
    d = heappop(q)
    # print(d.value, d.count)
    chg = min(N - cnt, d.count)
    ans += chg * d.value
    cnt += chg
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 collections import Counter -from heapq import heapify, heappop, heappush - - -class Data: -    def __init__(self, value, count): -        self.value = value -        self.count = count - -    def __lt__(self, other): -        return self.value > other.value - -    # 降順に取り出す - +from heapq import heapify, heappush, heappop -q = list() -heapify(q) -for v, c in list(Counter(a).items()): -    heappush(q, Data(v, c)) +hq = list([(-x, 1) for x in a]) +heapify(hq) -    c, v = list(map(int, input().split())) -    heappush(q, Data(v, c)) +    b, c = list(map(int, input().split())) +    heappush(hq, (-c, b)) +rest = N -cnt = 0 -while cnt < N: -    d = heappop(q) -    # print(d.value, d.count) -    chg = min(N - cnt, d.count) -    ans += chg * d.value -    cnt += chg +while rest > 0 and hq: +    mv, b = heappop(hq) +    mv *= -1 +    use = min(rest, b) +    ans += mv * use +    rest -= use