N,M = map(int,input().split())
A = list(map(int,input().split()))
CB = []
for i in range(0,M,1):
    b,c = map(int,input().split())
    CB.append([c,b])
A.sort()
CB.sort(reverse=True)

L = 0
ans = 0
owaowari = False
for i in range(0,M,1):
    for j in range(L,min(N,L+CB[i][1]),1):
        if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
    if owaowari or L > N-1:
        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 CB = [] CB [] for i in range(0,M,1):
    b,c = map(int,input().split())
    CB.append([c,b]) i range(0,M,1) range 0 M 1 b,c = map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c CB.append([c,b]) CB.append CB append [c,b] c b A.sort() A.sort A sort CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True L = 0 L 0 ans = 0 ans 0 owaowari = False owaowari False for i in range(0,M,1):
    for j in range(L,min(N,L+CB[i][1]),1):
        if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
    if owaowari or L > N-1:
        break i range(0,M,1) range 0 M 1 for j in range(L,min(N,L+CB[i][1]),1):
        if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
     j range(L,min(N,L+CB[i][1]),1) range L min(N,L+CB[i][1]) min N L+CB[i][1] L CB[i][1] [i] CB i 1 1 if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
     A[j] < CB[i][0] A[j] A j CB[i][0] [i] CB i 0 L = j+1 L j+1 j 1 A[j]=CB[i][0] A[j] A j CB[i][0] [i] CB i 0 owaowari = True owaowari True if owaowari or L > N-1:
        break owaowari or L > N-1 owaowari L > N-1 L N-1 N 1 break print(sum(A)) print sum(A) sum A L = 0 0 L ans = 0 0 ans A = list(map(int,input().split())) list(map(int,input().split())) A owaowari = True True owaowari CB = [] [] CB L = j+1 j+1 L N,M = map(int,input().split()) map(int,input().split()) N M = map(int,input().split()) map(int,input().split()) M b,c = map(int,input().split()) map(int,input().split()) b owaowari = False False owaowari c = map(int,input().split()) map(int,input().split()) c
N,M = map(int,input().split())
A = list(map(int,input().split()))
CB = []
for i in range(0,M,1):
    b,c = map(int,input().split())
    CB.append([c,b])
A.sort()
CB.sort(reverse=True)

L = 0
ans = 0
owaowari = False
for i in range(0,M,1):
    for j in range(L,min(N,L+CB[i][1]),1):
        if A[j] < CB[i][0]:
            L = j+1
            A[j]=CB[i][0]
        else:
            owaowari = True
    if owaowari or L > N-1:
        break
print(sum(A))