n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = sum(a)

bc = [[] for _ in range(m)]
for i in range(m):
    b, c = map(int, input().split())
    bc[i] = [b, c]
bc = sorted(bc, key=lambda x : x[1], reverse=True)

i = 0
for b, c in bc:
    for j in range(1, b+1):
        if i >= n:
            print(s)
            quit()
        next = s - a[i] + c
        if next > s:
            s = next
            i += 1
        else:
            print(s)
            quit()
print(s) 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 a.sort() a.sort a sort s = sum(a) s sum(a) sum a [] for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [] bc = [[] for _ in range(m)] bc [[] for _ in range(m)] for i in range(m):
    b, c = map(int, input().split())
    bc[i] = [b, c] i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c bc[i] = [b, c] bc[i] bc i [b, c] b c bc = sorted(bc, key=lambda x : x[1], reverse=True) bc sorted(bc, key=lambda x : x[1], reverse=True) sorted bc key=lambda x : x[1] key lambda x : x[1] x[1] x 1 x reverse=True reverse True i = 0 i 0 for b, c in bc:
    for j in range(1, b+1):
        if i >= n:
            print(s)
            quit()
        next = s - a[i] + c
        if next > s:
            s = next
            i += 1
        else:
            print(s)
            quit() b c bc for j in range(1, b+1):
        if i >= n:
            print(s)
            quit()
        next = s - a[i] + c
        if next > s:
            s = next
            i += 1
        else:
            print(s)
            quit() j range(1, b+1) range 1 b+1 b 1 if i >= n:
            print(s)
            quit()
         i >= n i n print(s) print s quit() quit next = s - a[i] + c next s - a[i] + c s - a[i] s a[i] a i c if next > s:
            s = next
            i += 1
        else:
            print(s)
            quit() next > s next s s = next s next i += 1 i 1 print(s) print s quit() quit print(s) print s s = sum(a) sum(a) s bc = sorted(bc, key=lambda x : x[1], reverse=True) sorted(bc, key=lambda x : x[1], reverse=True) bc c = map(int, input().split()) map(int, input().split()) c next = s - a[i] + c s - a[i] + c next i = 0 0 i m = map(int, input().split()) map(int, input().split()) m b, c = map(int, input().split()) map(int, input().split()) b n, m = map(int, input().split()) map(int, input().split()) n a = list(map(int, input().split())) list(map(int, input().split())) a bc = [[] for _ in range(m)] [[] for _ in range(m)] bc i += 1 1 i s = next next s
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = sum(a)

bc = [[] for _ in range(m)]
for i in range(m):
    b, c = map(int, input().split())
    bc[i] = [b, c]
bc = sorted(bc, key=lambda x : x[1], reverse=True)

i = 0
for b, c in bc:
    for j in range(1, b+1):
        if i >= n:
            print(s)
            quit()
        next = s - a[i] + c
        if next > s:
            s = next
            i += 1
        else:
            print(s)
            quit()
print(s)