import sys



N, M = list(map(int, sys.stdin.readline().split()))

a_list = list(map(int, sys.stdin.readline().split()))

items = []

for i in range(M):

    items.append(tuple(map(int, sys.stdin.readline().split())))





from collections import defaultdict



tar = defaultdict(int)

for a in a_list:

    tar[a] += 1



for i in range(M):

    b, c = items[i]

    tar[c] += b



tar = sorted(list(tar.items()), key=lambda x: -x[0])



cnt = 0

ans = 0

for k, v in tar:

    if cnt + v <= N:

        cnt +=v

        ans += k*v

    else:

        ans += k*(N-cnt)

        cnt = N

    if cnt >= N:

        break

print(ans)

import sys



N, M = list(map(int, sys.stdin.readline().split()))

a_list = list(map(int, sys.stdin.readline().split()))

items = []

for i in range(M):

    items.append(tuple(map(int, sys.stdin.readline().split())))



from heapq import *



que = []



for i in range(N):

    a = a_list[i]

    heappush(que, (-a, 1))



for b, c in items:

    heappush(que, (-c, b))



cnt = 0

ans = 0

while cnt < N:

    k, v = heappop(que)

    if cnt + v <= N:

        cnt += v

        ans += -(k * v)

    else:

        ans += -(k) * (N-cnt)

        cnt = N

print(ans)

import sys

N, M = list(map(int, sys.stdin.readline().split()))
a_list = list(map(int, sys.stdin.readline().split()))
items = []
for i in range(M):
    items.append(tuple(map(int, sys.stdin.readline().split())))
from collections import defaultdict

tar = defaultdict(int)
for a in a_list:
    tar[a] += 1
for i in range(M):
    b, c = items[i]
    tar[c] += b
tar = sorted(list(tar.items()), key=lambda x: -x[0])
cnt = 0
ans = 0
for k, v in tar:
    if cnt + v <= N:
        cnt += v
        ans += k * v
    else:
        ans += k * (N - cnt)
        cnt = N
    if cnt >= N:
        break
print(ans)

import sys

N, M = list(map(int, sys.stdin.readline().split()))
a_list = list(map(int, sys.stdin.readline().split()))
items = []
for i in range(M):
    items.append(tuple(map(int, sys.stdin.readline().split())))
from heapq import *

que = []
for i in range(N):
    a = a_list[i]
    heappush(que, (-a, 1))
for b, c in items:
    heappush(que, (-c, b))
cnt = 0
ans = 0
while cnt < N:
    k, v = heappop(que)
    if cnt + v <= N:
        cnt += v
        ans += -(k * v)
    else:
        ans += -(k) * (N - cnt)
        cnt = N
print(ans)

-from collections import defaultdict +from heapq import * -tar = defaultdict(int) -for a in a_list: -    tar[a] += 1 -for i in range(M): -    b, c = items[i] -    tar[c] += b -tar = sorted(list(tar.items()), key=lambda x: -x[0]) +que = [] +for i in range(N): +    a = a_list[i] +    heappush(que, (-a, 1)) +for b, c in items: +    heappush(que, (-c, b)) -for k, v in tar: +while cnt < N: +    k, v = heappop(que) -        ans += k * v +        ans += -(k * v) -        ans += k * (N - cnt) +        ans += -(k) * (N - cnt) -    if cnt >= N: -        break