n,m = map(int,input().split())
a = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
l = list(sorted(l,reverse=True,key=lambda x: x[1]))
b,c = [list(i) for i in zip(*l)]
d = [0] * n
x = min(n,sum(b))
y = 0
while x > 0:
    x -= 1
    d[x] = c[y]
    b[y] -= 1
    if b[y] == 0:
        y += 1
x = a + d
x.sort(reverse=True)
print(sum(x[:n])) 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 list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l = [list(map(int,input().split())) for i in range(m)] l [list(map(int,input().split())) for i in range(m)] l = list(sorted(l,reverse=True,key=lambda x: x[1])) l list(sorted(l,reverse=True,key=lambda x: x[1])) list sorted(l,reverse=True,key=lambda x: x[1]) sorted l reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x list(i) for i in zip(*l) for i in zip(*l) i zip(*l) zip *l l for i in zip(*l) list(i) list i b,c = [list(i) for i in zip(*l)] b [list(i) for i in zip(*l)] c d = [0] * n d [0] * n [0] 0 n x = min(n,sum(b)) x min(n,sum(b)) min n sum(b) sum b y = 0 y 0 while x > 0:
    x -= 1
    d[x] = c[y]
    b[y] -= 1
    if b[y] == 0:
        y += 1 x > 0 x 0 x -= 1 x 1 d[x] = c[y] d[x] d x c[y] c y b[y] -= 1 b[y] b y 1 if b[y] == 0:
        y += 1 b[y] == 0 b[y] b y 0 y += 1 y 1 x = a + d x a + d a d x.sort(reverse=True) x.sort x sort reverse=True reverse True print(sum(x[:n])) print sum(x[:n]) sum x[:n] x :n n y = 0 0 y x -= 1 1 x x = min(n,sum(b)) min(n,sum(b)) x y += 1 1 y l = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] l n,m = map(int,input().split()) map(int,input().split()) n c = [list(i) for i in zip(*l)] [list(i) for i in zip(*l)] c l = list(sorted(l,reverse=True,key=lambda x: x[1])) list(sorted(l,reverse=True,key=lambda x: x[1])) l x = a + d a + d x b,c = [list(i) for i in zip(*l)] [list(i) for i in zip(*l)] b d = [0] * n [0] * n d m = map(int,input().split()) map(int,input().split()) m a = list(map(int,input().split())) list(map(int,input().split())) a
n,m = map(int,input().split())
a = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
l = list(sorted(l,reverse=True,key=lambda x: x[1]))
b,c = [list(i) for i in zip(*l)]
d = [0] * n
x = min(n,sum(b))
y = 0
while x > 0:
    x -= 1
    d[x] = c[y]
    b[y] -= 1
    if b[y] == 0:
        y += 1
x = a + d
x.sort(reverse=True)
print(sum(x[:n]))