n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
c = [[] for _ in range(m)]
for i in range(m):
    c[i] = list(map(int, input().split()))
a.sort()
c.sort(key=lambda x: x[1], reverse=True)
ans = sum(a)
sa = 0
cnt = 0
r = c[0][0]
for i, v in enumerate(a):
    if r <= i and cnt <= m - 2:
        cnt += 1
        r += c[cnt][0]
    if r > i and v < c[cnt][1]:
        ans += abs(c[cnt][1] - v)
    else:
        break
print(ans) n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 [] for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [] c = [[] for _ in range(m)] c [[] for _ in range(m)] for i in range(m):
    c[i] = list(map(int, input().split())) i range(m) range m c[i] = list(map(int, input().split())) c[i] c i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split a.sort() a.sort a sort c.sort(key=lambda x: x[1], reverse=True) c.sort c sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True ans = sum(a) ans sum(a) sum a sa = 0 sa 0 cnt = 0 cnt 0 r = c[0][0] r c[0][0] [0] c 0 0 for i, v in enumerate(a):
    if r <= i and cnt <= m - 2:
        cnt += 1
        r += c[cnt][0]
    if r > i and v < c[cnt][1]:
        ans += abs(c[cnt][1] - v)
    else:
        break i v enumerate(a) enumerate a if r <= i and cnt <= m - 2:
        cnt += 1
        r += c[cnt][0]
     r <= i and cnt <= m - 2 r <= i r i cnt <= m - 2 cnt m - 2 m 2 cnt += 1 cnt 1 r += c[cnt][0] r c[cnt][0] [cnt] c cnt 0 if r > i and v < c[cnt][1]:
        ans += abs(c[cnt][1] - v)
    else:
        break r > i and v < c[cnt][1] r > i r i v < c[cnt][1] v c[cnt][1] [cnt] c cnt 1 ans += abs(c[cnt][1] - v) ans abs(c[cnt][1] - v) abs c[cnt][1] - v c[cnt][1] [cnt] c cnt 1 v break print(ans) print ans cnt += 1 1 cnt a = list(map(int, input().split())) list(map(int, input().split())) a ans += abs(c[cnt][1] - v) abs(c[cnt][1] - v) ans cnt = 0 0 cnt r = c[0][0] c[0][0] r n, m = list(map(int, input().split())) list(map(int, input().split())) n c = [[] for _ in range(m)] [[] for _ in range(m)] c m = list(map(int, input().split())) list(map(int, input().split())) m ans = sum(a) sum(a) ans sa = 0 0 sa r += c[cnt][0] c[cnt][0] r
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
c = [[] for _ in range(m)]
for i in range(m):
    c[i] = list(map(int, input().split()))
a.sort()
c.sort(key=lambda x: x[1], reverse=True)
ans = sum(a)
sa = 0
cnt = 0
r = c[0][0]
for i, v in enumerate(a):
    if r <= i and cnt <= m - 2:
        cnt += 1
        r += c[cnt][0]
    if r > i and v < c[cnt][1]:
        ans += abs(c[cnt][1] - v)
    else:
        break
print(ans)
