from collections import defaultdict
n, m = map(int, input().split())
a = list(map(int, input().split()))
b, c = [0] * m, [0] * m
data = defaultdict(int)
for i in range(m):
    b[i], c[i] = map(int, input().split())
    data[c[i]] += b[i]

for x in a:
    data[x] += 1
data = sorted(data.items(), key = lambda x: x[0])
i = len(data) - 1
cnt = 0
ans = 0
while 1:
    x = min(n - cnt, data[i][1])
    ans += x * data[i][0]
    i -= 1
    cnt += x
    if cnt == n:
        break
print(ans) from collections import defaultdict n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b, c = [0] * m, [0] * m b [0] * m [0] 0 m c [0] * m [0] 0 m data = defaultdict(int) data defaultdict(int) defaultdict int for i in range(m):
    b[i], c[i] = map(int, input().split())
    data[c[i]] += b[i] i range(m) range m b[i], c[i] = map(int, input().split()) b[i] b i map(int, input().split()) map int input().split() ().split () input split c[i] c i data[c[i]] += b[i] data[c[i]] data c[i] c i b[i] b i for x in a:
    data[x] += 1 x a data[x] += 1 data[x] data x 1 data = sorted(data.items(), key = lambda x: x[0]) data sorted(data.items(), key = lambda x: x[0]) sorted data.items() data.items data items key = lambda x: x[0] key lambda x: x[0] x[0] x 0 x i = len(data) - 1 i len(data) - 1 len(data) len data 1 cnt = 0 cnt 0 ans = 0 ans 0 while 1:
    x = min(n - cnt, data[i][1])
    ans += x * data[i][0]
    i -= 1
    cnt += x
    if cnt == n:
        break 1 x = min(n - cnt, data[i][1]) x min(n - cnt, data[i][1]) min n - cnt n cnt data[i][1] [i] data i 1 ans += x * data[i][0] ans x * data[i][0] x data[i][0] [i] data i 0 i -= 1 i 1 cnt += x cnt x if cnt == n:
        break cnt == n cnt n break print(ans) print ans c = [0] * m, [0] * m [0] * m c data = sorted(data.items(), key = lambda x: x[0]) sorted(data.items(), key = lambda x: x[0]) data data = defaultdict(int) defaultdict(int) data cnt = 0 0 cnt a = list(map(int, input().split())) list(map(int, input().split())) a i = len(data) - 1 len(data) - 1 i ans += x * data[i][0] x * data[i][0] ans m = map(int, input().split()) map(int, input().split()) m b, c = [0] * m, [0] * m [0] * m b n, m = map(int, input().split()) map(int, input().split()) n cnt += x x cnt x = min(n - cnt, data[i][1]) min(n - cnt, data[i][1]) x ans = 0 0 ans i -= 1 1 i
from collections import defaultdict
n, m = map(int, input().split())
a = list(map(int, input().split()))
b, c = [0] * m, [0] * m
data = defaultdict(int)
for i in range(m):
    b[i], c[i] = map(int, input().split())
    data[c[i]] += b[i]

for x in a:
    data[x] += 1
data = sorted(data.items(), key = lambda x: x[0])
i = len(data) - 1
cnt = 0
ans = 0
while 1:
    x = min(n - cnt, data[i][1])
    ans += x * data[i][0]
    i -= 1
    cnt += x
    if cnt == n:
        break
print(ans)
