n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = [tuple(map(int, input().split())) for _ in range(m)]
d.sort(key=lambda p: -p[1])
now = 0
for b, c in d:
    while b > 0:
        if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
    if now == len(a):
        break
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 tuple(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split d = [tuple(map(int, input().split())) for _ in range(m)] d [tuple(map(int, input().split())) for _ in range(m)] d.sort(key=lambda p: -p[1]) d.sort d sort key=lambda p: -p[1] key lambda p: -p[1] -p[1] p[1] p 1 p now = 0 now 0 for b, c in d:
    while b > 0:
        if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
    if now == len(a):
        break b c d while b > 0:
        if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
     b > 0 b 0 if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
     c > a[now] c a[now] a now a[now] = c a[now] a now c now += 1 now 1 b -= 1 b 1 if now == len(a):
                break
         now == len(a) now len(a) len a break break if now == len(a):
        break now == len(a) now len(a) len a break print(sum(a)) print sum(a) sum a b -= 1 1 b n, m = map(int, input().split()) map(int, input().split()) n now += 1 1 now d = [tuple(map(int, input().split())) for _ in range(m)] [tuple(map(int, input().split())) for _ in range(m)] d m = map(int, input().split()) map(int, input().split()) m a = list(map(int, input().split())) list(map(int, input().split())) a now = 0 0 now
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
d = [tuple(map(int, input().split())) for _ in range(m)]
d.sort(key=lambda p: -p[1])
now = 0
for b, c in d:
    while b > 0:
        if c > a[now]:
            a[now] = c
            now += 1
            b -= 1
            if now == len(a):
                break
        else:
            break
    if now == len(a):
        break
print(sum(a))
