from collections import deque

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

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

a.sort(reverse = False)
bc.sort(key = lambda x: x[1], reverse = True)

q = deque(bc)

s = 0

b, c = q.popleft()

for x in a:
    #print(x, b, c)
    if b == 0:
        if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
    if x < c:
        s += c
        b -= 1
    else:
        s += x

print(s) from collections import deque n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [list(map(int, input().split())) for _ in range(m)] bc [list(map(int, input().split())) for _ in range(m)] a.sort(reverse = False) a.sort a sort reverse = False reverse False bc.sort(key = lambda x: x[1], reverse = True) bc.sort bc sort key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse = True reverse True q = deque(bc) q deque(bc) deque bc s = 0 s 0 b, c = q.popleft() b q.popleft() q.popleft q popleft c for x in a:
    #print(x, b, c)
    if b == 0:
        if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
    if x < c:
        s += c
        b -= 1
    else:
        s += x x a if b == 0:
        if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
     b == 0 b 0 if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
     len(q) > 0 len(q) len q 0 b, c = q.popleft() b q.popleft() q.popleft q popleft c b, c = n, 0 b n c 0 if x < c:
        s += c
        b -= 1
    else:
        s += x x < c x c s += c s c b -= 1 b 1 s += x s x print(s) print s s = 0 0 s c = n, 0 0 c b -= 1 1 b q = deque(bc) deque(bc) q b, c = n, 0 n b s += x x s s += c c s n, m = list(map(int, input().split())) list(map(int, input().split())) n m = list(map(int, input().split())) list(map(int, input().split())) m b, c = q.popleft() q.popleft() b a = list(map(int, input().split())) list(map(int, input().split())) a c = q.popleft() q.popleft() c c = q.popleft() q.popleft() c b, c = q.popleft() q.popleft() b bc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc
from collections import deque

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

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

a.sort(reverse = False)
bc.sort(key = lambda x: x[1], reverse = True)

q = deque(bc)

s = 0

b, c = q.popleft()

for x in a:
    #print(x, b, c)
    if b == 0:
        if len(q) > 0:
            b, c = q.popleft()
        else:
            b, c = n, 0
    
    if x < c:
        s += c
        b -= 1
    else:
        s += x

print(s)