import collections

N, M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()
op = [0]*M

for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b)

op.sort(reverse=True)

now = 0
flag = False
for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if now >= N:
        break
    if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
    
print(sum(A)) import collections collections 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 A.sort() A.sort A sort op = [0]*M op [0]*M [0] 0 M for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b) i range(M) range M b,c = map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c op[i] = (c, b) op[i] op i (c, b) c b op.sort(reverse=True) op.sort op sort reverse=True reverse True now = 0 now 0 flag = False flag False for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if now >= N:
        break
    if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
     i range(M) range M if flag:
        break
     flag break val, maisu = op[i] val op[i] op i maisu if now >= N:
        break
     now >= N now N break if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
     A[now] < val A[now] A now val for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
         j range(maisu) range maisu if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
         now+j < N now+j now j N if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
         A[now+j] < val A[now+j] A now+j now j val A[now+j] = val A[now+j] A now+j now j val flag = True flag True break now += maisu now maisu break print(sum(A)) print sum(A) sum A b,c = map(int,input().split()) map(int,input().split()) b now += maisu maisu now A = list(map(int,input().split())) list(map(int,input().split())) A maisu = op[i] op[i] maisu val, maisu = op[i] op[i] val now = 0 0 now M = map(int,input().split()) map(int,input().split()) M c = map(int,input().split()) map(int,input().split()) c flag = True True flag op = [0]*M [0]*M op N, M = map(int,input().split()) map(int,input().split()) N flag = False False flag
import collections

N, M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()
op = [0]*M

for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b)

op.sort(reverse=True)

now = 0
flag = False
for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if now >= N:
        break
    if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
    
print(sum(A))