n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
bc = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
x, y = 0, 0
for i in range(n):
    if y == m or a[x] > bc[y][1]:
        ans += a[x]
        x += 1
    else:
        ans += bc[y][1]
        bc[y][0] -= 1
        if bc[y][0] == 0:
            y += 1
print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = sorted(list(map(int, input().split())), reverse=True) a sorted(list(map(int, input().split())), reverse=True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True) bc sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True) sorted [list(map(int, input().split())) for i in range(m)] key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True ans = 0 ans 0 x, y = 0, 0 x 0 y 0 for i in range(n):
    if y == m or a[x] > bc[y][1]:
        ans += a[x]
        x += 1
    else:
        ans += bc[y][1]
        bc[y][0] -= 1
        if bc[y][0] == 0:
            y += 1 i range(n) range n if y == m or a[x] > bc[y][1]:
        ans += a[x]
        x += 1
    else:
        ans += bc[y][1]
        bc[y][0] -= 1
        if bc[y][0] == 0:
            y += 1 y == m or a[x] > bc[y][1] y == m y m a[x] > bc[y][1] a[x] a x bc[y][1] [y] bc y 1 ans += a[x] ans a[x] a x x += 1 x 1 ans += bc[y][1] ans bc[y][1] [y] bc y 1 bc[y][0] -= 1 bc[y][0] [y] bc y 0 1 if bc[y][0] == 0:
            y += 1 bc[y][0] == 0 bc[y][0] [y] bc y 0 0 y += 1 y 1 print(ans) print ans x, y = 0, 0 0 x ans += a[x] a[x] ans y = 0, 0 0 y n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m ans = 0 0 ans ans += bc[y][1] bc[y][1] ans x += 1 1 x bc = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True) sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True) bc a = sorted(list(map(int, input().split())), reverse=True) sorted(list(map(int, input().split())), reverse=True) a y += 1 1 y
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
bc = sorted([list(map(int, input().split())) for i in range(m)], key=lambda x:x[1], reverse=True)
ans = 0
x, y = 0, 0
for i in range(n):
    if y == m or a[x] > bc[y][1]:
        ans += a[x]
        x += 1
    else:
        ans += bc[y][1]
        bc[y][0] -= 1
        if bc[y][0] == 0:
            y += 1
print(ans)