from operator import itemgetter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(i) for i in input().split()) for _ in range(m)]

a.sort()
bc.sort(key=itemgetter(1), reverse=True)
idx = 0
b, c = bc[idx]
for i in range(n):
    if a[i] >= c:
        break
    a[i] = c
    b -= 1

    if b == 0:
        idx += 1
        if idx >= m:
            break
        b, c = bc[idx]

print(sum(a)) from operator import itemgetter 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 tuple(int(i) for i in input().split()) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) tuple(int(i) for i in input().split()) tuple int(i) int i bc = [tuple(int(i) for i in input().split()) for _ in range(m)] bc [tuple(int(i) for i in input().split()) for _ in range(m)] a.sort() a.sort a sort bc.sort(key=itemgetter(1), reverse=True) bc.sort bc sort key=itemgetter(1) key itemgetter(1) itemgetter 1 reverse=True reverse True idx = 0 idx 0 b, c = bc[idx] b bc[idx] bc idx c for i in range(n):
    if a[i] >= c:
        break
    a[i] = c
    b -= 1

    if b == 0:
        idx += 1
        if idx >= m:
            break
        b, c = bc[idx] i range(n) range n if a[i] >= c:
        break
     a[i] >= c a[i] a i c break a[i] = c a[i] a i c b -= 1 b 1 if b == 0:
        idx += 1
        if idx >= m:
            break
        b, c = bc[idx] b == 0 b 0 idx += 1 idx 1 if idx >= m:
            break
         idx >= m idx m break b, c = bc[idx] b bc[idx] bc idx c print(sum(a)) print sum(a) sum a n, m = map(int, input().split()) map(int, input().split()) n bc = [tuple(int(i) for i in input().split()) for _ in range(m)] [tuple(int(i) for i in input().split()) for _ in range(m)] bc a = list(map(int, input().split())) list(map(int, input().split())) a b, c = bc[idx] bc[idx] b m = map(int, input().split()) map(int, input().split()) m b, c = bc[idx] bc[idx] b c = bc[idx] bc[idx] c idx = 0 0 idx c = bc[idx] bc[idx] c b -= 1 1 b idx += 1 1 idx
from operator import itemgetter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(int(i) for i in input().split()) for _ in range(m)]

a.sort()
bc.sort(key=itemgetter(1), reverse=True)
idx = 0
b, c = bc[idx]
for i in range(n):
    if a[i] >= c:
        break
    a[i] = c
    b -= 1

    if b == 0:
        idx += 1
        if idx >= m:
            break
        b, c = bc[idx]

print(sum(a))
