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

cb = []
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c, b])
cb = list(reversed(sorted(cb)))

c, b = 0, 0
for i in range(n):
    if b <= 0:
        if len(cb) == 0:
            break
        c, b = cb.pop(0)
    if c <= a[i]:
        break
    a[i] = c
    b -= 1
print(sum(a)) 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 cb = [] cb [] for i in range(m):
    b, c = map(int, input().split())
    cb.append([c, b]) i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c cb.append([c, b]) cb.append cb append [c, b] c b cb = list(reversed(sorted(cb))) cb list(reversed(sorted(cb))) list reversed(sorted(cb)) reversed sorted(cb) sorted cb c, b = 0, 0 c 0 b 0 for i in range(n):
    if b <= 0:
        if len(cb) == 0:
            break
        c, b = cb.pop(0)
    if c <= a[i]:
        break
    a[i] = c
    b -= 1 i range(n) range n if b <= 0:
        if len(cb) == 0:
            break
        c, b = cb.pop(0)
     b <= 0 b 0 if len(cb) == 0:
            break
         len(cb) == 0 len(cb) len cb 0 break c, b = cb.pop(0) c cb.pop(0) cb.pop cb pop 0 b if c <= a[i]:
        break
     c <= a[i] c a[i] a i break a[i] = c a[i] a i c b -= 1 b 1 print(sum(a)) print sum(a) sum a cb = list(reversed(sorted(cb))) list(reversed(sorted(cb))) cb c, b = cb.pop(0) cb.pop(0) c n,m = map(int, input().split()) map(int, input().split()) n c = map(int, input().split()) map(int, input().split()) c b = 0, 0 0 b cb = [] [] cb a = list(map(int, input().split())) list(map(int, input().split())) a m = map(int, input().split()) map(int, input().split()) m c, b = 0, 0 0 c b = cb.pop(0) cb.pop(0) b b -= 1 1 b b, c = map(int, input().split()) map(int, input().split()) b
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

cb = []
for i in range(m):
    b, c = map(int, input().split())
    cb.append([c, b])
cb = list(reversed(sorted(cb)))

c, b = 0, 0
for i in range(n):
    if b <= 0:
        if len(cb) == 0:
            break
        c, b = cb.pop(0)
    if c <= a[i]:
        break
    a[i] = c
    b -= 1
print(sum(a))
