N , M = (int(a) for a in input().split())
A = list(map(int,input().split()))
BC = [[int(a) for a in input().split()] for l in range(M)]
A =sorted(A)
BC = sorted(BC , key = lambda x: - x[1])
s = 0

for i in range(N*M) :
    if A[i] < BC[s][1] :
        A[i] = BC[s][1]
    else : break
    BC[s][0] -= 1
    if BC [-1][0] == 0 or i == N-1 :
        break
    if BC[s][0] == 0 :
        s += 1

print(sum(A))


 int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a N , M = (int(a) for a in input().split()) N (int(a) for a in 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 [int(a) for a in input().split()] for l in range(M) for l in range(M) l range(M) range M for l in range(M) [int(a) for a in input().split()] BC = [[int(a) for a in input().split()] for l in range(M)] BC [[int(a) for a in input().split()] for l in range(M)] A =sorted(A) A sorted(A) sorted A BC = sorted(BC , key = lambda x: - x[1]) BC sorted(BC , key = lambda x: - x[1]) sorted BC key = lambda x: - x[1] key lambda x: - x[1] - x[1] x[1] x 1 x s = 0 s 0 for i in range(N*M) :
    if A[i] < BC[s][1] :
        A[i] = BC[s][1]
    else : break
    BC[s][0] -= 1
    if BC [-1][0] == 0 or i == N-1 :
        break
    if BC[s][0] == 0 :
        s += 1 i range(N*M) range N*M N M if A[i] < BC[s][1] :
        A[i] = BC[s][1]
    else : break
     A[i] < BC[s][1] A[i] A i BC[s][1] [s] BC s 1 A[i] = BC[s][1] A[i] A i BC[s][1] [s] BC s 1 BC[s][0] -= 1 BC[s][0] [s] BC s 0 1 if BC [-1][0] == 0 or i == N-1 :
        break
     BC [-1][0] == 0 or i == N-1 BC [-1][0] == 0 BC [-1][0] [-1] BC -1 0 0 i == N-1 i N-1 N 1 break if BC[s][0] == 0 :
        s += 1 BC[s][0] == 0 BC[s][0] [s] BC s 0 0 s += 1 s 1 print(sum(A)) print sum(A) sum A s += 1 1 s M = (int(a) for a in input().split()) (int(a) for a in input().split()) M A =sorted(A) sorted(A) A BC = [[int(a) for a in input().split()] for l in range(M)] [[int(a) for a in input().split()] for l in range(M)] BC N , M = (int(a) for a in input().split()) (int(a) for a in input().split()) N BC = sorted(BC , key = lambda x: - x[1]) sorted(BC , key = lambda x: - x[1]) BC A = list(map(int,input().split())) list(map(int,input().split())) A s = 0 0 s
N , M = (int(a) for a in input().split())
A = list(map(int,input().split()))
BC = [[int(a) for a in input().split()] for l in range(M)]
A =sorted(A)
BC = sorted(BC , key = lambda x: - x[1])
s = 0

for i in range(N*M) :
    if A[i] < BC[s][1] :
        A[i] = BC[s][1]
    else : break
    BC[s][0] -= 1
    if BC [-1][0] == 0 or i == N-1 :
        break
    if BC[s][0] == 0 :
        s += 1

print(sum(A))



