n, m = map(int, input().split())
a = list(map(int, input().split()))
d = []
e = 0; f = 0; g = 0
for _ in range(m):
    b, c = map(int, input().split())
    d.append([c, b])
a.sort()
d.sort(reverse=True)
for i in range(len(d)):
    for _ in range(d[i][1]):
        if a[e] < d[i][0]:
            a[e] = d[i][0]
        else:
            f = 1
            break
        e += 1
        if e == n:
            f = 1
            break
    if f == 1: break
for i in range(n): g += a[i]
print(g) 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 d = [] d [] e = 0 e 0 f = 0 f 0 g = 0 g 0 for _ in range(m):
    b, c = map(int, input().split())
    d.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 d.append([c, b]) d.append d append [c, b] c b a.sort() a.sort a sort d.sort(reverse=True) d.sort d sort reverse=True reverse True for i in range(len(d)):
    for _ in range(d[i][1]):
        if a[e] < d[i][0]:
            a[e] = d[i][0]
        else:
            f = 1
            break
        e += 1
        if e == n:
            f = 1
            break
    if f == 1: break i range(len(d)) range len(d) len d for _ in range(d[i][1]):
        if a[e] < d[i][0]:
            a[e] = d[i][0]
        else:
            f = 1
            break
        e += 1
        if e == n:
            f = 1
            break
     _ range(d[i][1]) range d[i][1] [i] d i 1 if a[e] < d[i][0]:
            a[e] = d[i][0]
        else:
            f = 1
            break
         a[e] < d[i][0] a[e] a e d[i][0] [i] d i 0 a[e] = d[i][0] a[e] a e d[i][0] [i] d i 0 f = 1 f 1 break e += 1 e 1 if e == n:
            f = 1
            break
     e == n e n f = 1 f 1 break if f == 1: b f == 1 f 1 for i in range(n): g += a[i] i range(n) range n print(g) print g f = 0 0 f f = 1 1 f e = 0 0 e g = 0 0 g e += 1 1 e a = list(map(int, input().split())) list(map(int, input().split())) a f = 1 1 f m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n c = map(int, input().split()) map(int, input().split()) c b, c = map(int, input().split()) map(int, input().split()) b d = [] [] d
n, m = map(int, input().split())
a = list(map(int, input().split()))
d = []
e = 0; f = 0; g = 0
for _ in range(m):
    b, c = map(int, input().split())
    d.append([c, b])
a.sort()
d.sort(reverse=True)
for i in range(len(d)):
    for _ in range(d[i][1]):
        if a[e] < d[i][0]:
            a[e] = d[i][0]
        else:
            f = 1
            break
        e += 1
        if e == n:
            f = 1
            break
    if f == 1: break
for i in range(n): g += a[i]
print(g)