n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    b, c = map(int, input().split())
    bc.append([c, b])
a.sort()
bc.sort(reverse = True)
x = [0] * n
i, j = 0, 0
while i < n:
    for _ in range(bc[j][1]):
        x[i] = bc[j][0]
        i += 1
        if i == n:
            break
    j += 1
    if j == m:
        break
ans = 0
for i in range(n):
    ans += max(a[i], x[i])
print(ans) 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 bc = [] bc [] for _ in range(m):
    b, c = map(int, input().split())
    bc.append([c, b]) _ range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c bc.append([c, b]) bc.append bc append [c, b] c b a.sort() a.sort a sort bc.sort(reverse = True) bc.sort bc sort reverse = True reverse True x = [0] * n x [0] * n [0] 0 n i, j = 0, 0 i 0 j 0 while i < n:
    for _ in range(bc[j][1]):
        x[i] = bc[j][0]
        i += 1
        if i == n:
            break
    j += 1
    if j == m:
        break i < n i n for _ in range(bc[j][1]):
        x[i] = bc[j][0]
        i += 1
        if i == n:
            break
     _ range(bc[j][1]) range bc[j][1] [j] bc j 1 x[i] = bc[j][0] x[i] x i bc[j][0] [j] bc j 0 i += 1 i 1 if i == n:
            break
     i == n i n break j += 1 j 1 if j == m:
        break j == m j m break ans = 0 ans 0 for i in range(n):
    ans += max(a[i], x[i]) i range(n) range n ans += max(a[i], x[i]) ans max(a[i], x[i]) max a[i] a i x[i] x i print(ans) print ans j = 0, 0 0 j m = map(int, input().split()) map(int, input().split()) m ans = 0 0 ans ans += max(a[i], x[i]) max(a[i], x[i]) ans n, m = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b i, j = 0, 0 0 i a = list(map(int, input().split())) list(map(int, input().split())) a j += 1 1 j c = map(int, input().split()) map(int, input().split()) c i += 1 1 i bc = [] [] bc x = [0] * n [0] * n x
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    b, c = map(int, input().split())
    bc.append([c, b])
a.sort()
bc.sort(reverse = True)
x = [0] * n
i, j = 0, 0
while i < n:
    for _ in range(bc[j][1]):
        x[i] = bc[j][0]
        i += 1
        if i == n:
            break
    j += 1
    if j == m:
        break
ans = 0
for i in range(n):
    ans += max(a[i], x[i])
print(ans)