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

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



cb = []

for i in A:

    cb += [[i,1]]

for _ in range(M):

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

    cb += [[c, b]]

cb.sort(reverse = True)

#print (cb)



ans = 0

i = 0

j = 0

while i <= N:

    a = min(N-i, cb[j][1])

    ans += cb[j][0] * a

    j += 1

    i += a

    #print (ans)

    if i == N:

        print (ans)

        i += 1

import sys

input = sys.stdin.readline



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

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



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

BC_append = BC.append

for a in A:

    BC_append((1, a))



BC.sort(key = lambda x: x[1])



ans = 0

while N > 0:

    bc = BC.pop()

    b = bc[0]

    c = bc[1]

    if b > N:

        ans += c * N

        N = 0

    else:

        ans += c * b

        N -= b



print (ans)

    

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cb = []
for i in A:
    cb += [[i, 1]]
for _ in range(M):
    b, c = list(map(int, input().split()))
    cb += [[c, b]]
cb.sort(reverse=True)
# print (cb)
ans = 0
i = 0
j = 0
while i <= N:
    a = min(N - i, cb[j][1])
    ans += cb[j][0] * a
    j += 1
    i += a
    # print (ans)
    if i == N:
        print(ans)
        i += 1

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]
BC_append = BC.append
for a in A:
    BC_append((1, a))
BC.sort(key=lambda x: x[1])
ans = 0
while N > 0:
    bc = BC.pop()
    b = bc[0]
    c = bc[1]
    if b > N:
        ans += c * N
        N = 0
    else:
        ans += c * b
        N -= b
print(ans)

+import sys + +input = sys.stdin.readline -cb = [] -for i in A: -    cb += [[i, 1]] -for _ in range(M): -    b, c = list(map(int, input().split())) -    cb += [[c, b]] -cb.sort(reverse=True) -# print (cb) +BC = [tuple(map(int, input().split())) for _ in range(M)] +BC_append = BC.append +for a in A: +    BC_append((1, a)) +BC.sort(key=lambda x: x[1]) -i = 0 -j = 0 -while i <= N: -    a = min(N - i, cb[j][1]) -    ans += cb[j][0] * a -    j += 1 -    i += a -    # print (ans) -    if i == N: -        print(ans) -        i += 1 +while N > 0: +    bc = BC.pop() +    b = bc[0] +    c = bc[1] +    if b > N: +        ans += c * N +        N = 0 +    else: +        ans += c * b +        N -= b +print(ans)