n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = []
for _ in range(m):
    b, c = map(int, input().split())
    x.append([b, c])

x.sort(key=lambda p: p[1], reverse=True)

ret = 0
for b, c in x:
    if not a:
        break
    if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break

print(ret + 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(reverse=True) a.sort a sort reverse=True reverse True x = [] x [] for _ in range(m):
    b, c = map(int, input().split())
    x.append([b, c]) _ range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c x.append([b, c]) x.append x append [b, c] b c x.sort(key=lambda p: p[1], reverse=True) x.sort x sort key=lambda p: p[1] key lambda p: p[1] p[1] p 1 p reverse=True reverse True ret = 0 ret 0 for b, c in x:
    if not a:
        break
    if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break b c x if not a:
        break
     not a a break if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break c > a[-1] c a[-1] a -1 while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
     c > a[-1] c a[-1] a -1 ret += c ret c a.pop() a.pop a pop b -= 1 b 1 if b == 0:
                break
             b == 0 b 0 break if not a:
                break
     not a a break break print(ret + sum(a)) print ret + sum(a) ret sum(a) sum a b, c = map(int, input().split()) map(int, input().split()) b m = map(int, input().split()) map(int, input().split()) m ret = 0 0 ret a = list(map(int, input().split())) list(map(int, input().split())) a n, m = map(int, input().split()) map(int, input().split()) n x = [] [] x ret += c c ret c = map(int, input().split()) map(int, input().split()) c b -= 1 1 b
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = []
for _ in range(m):
    b, c = map(int, input().split())
    x.append([b, c])

x.sort(key=lambda p: p[1], reverse=True)

ret = 0
for b, c in x:
    if not a:
        break
    if c > a[-1]:
        while c > a[-1]:
            ret += c
            a.pop()
            b -= 1
            if b == 0:
                break
            if not a:
                break
    else:
        break

print(ret + sum(a))

