n, m =map(int,input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split()))for i in range(m)]

A.sort()
BC.sort(key= lambda x : -x[1])


i = 0
for b, c in BC:
    for _ in range(b):
        if c <=  A[i] : break
        A[i] = c
        i += 1
        if i >= n: break
    else:continue
    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 tuple(map(int,input().split()))for i in range(m) for i in range(m) i range(m) range m for i in range(m) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split BC = [tuple(map(int,input().split()))for i in range(m)] BC [tuple(map(int,input().split()))for i in range(m)] A.sort() A.sort A sort BC.sort(key= lambda x : -x[1]) BC.sort BC sort key= lambda x : -x[1] key lambda x : -x[1] -x[1] x[1] x 1 x i = 0 i 0 for b, c in BC:
    for _ in range(b):
        if c <=  A[i] : break
        A[i] = c
        i += 1
        if i >= n: break
    else:continue
    break b c BC for _ in range(b):
        if c <=  A[i] : break
        A[i] = c
        i += 1
        if i >= n: break
    else:continue
     _ range(b) range b if c <=  A[i] : break
         c <=  A[i] c A[i] A i A[i] = c A[i] A i c i += 1 i 1 if i >= n: break
     i >= n i n break print(sum(A)) print sum(A) sum A BC = [tuple(map(int,input().split()))for i in range(m)] [tuple(map(int,input().split()))for i in range(m)] BC n, m =map(int,input().split()) map(int,input().split()) n A = list(map(int,input().split())) list(map(int,input().split())) A m =map(int,input().split()) map(int,input().split()) m i = 0 0 i i += 1 1 i
n, m =map(int,input().split())
A = list(map(int,input().split()))
BC = [tuple(map(int,input().split()))for i in range(m)]

A.sort()
BC.sort(key= lambda x : -x[1])


i = 0
for b, c in BC:
    for _ in range(b):
        if c <=  A[i] : break
        A[i] = c
        i += 1
        if i >= n: break
    else:continue
    break
print(sum(A))