import numpy as np


N,M=map(int,input().split())
# A=np.array(list(map(int,input().split())))
A=np.array(list(map(int,input().split())),dtype=np.int32)
A=np.sort(A)

EXC=[]

for i in range(M):
    exc=list(map(int,input().split()))
    EXC.append(exc)
excArry=np.array(EXC,dtype=np.int32)

col_num=1
Arr=excArry[np.argsort(excArry[:,col_num])[::-1]]
# print(A)
# print(Arr)

point=0


for j in range (M):
    # change_Num=Arr[j][1]
    count=np.count_nonzero(A<Arr[j][1])
    if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=Arr[j][1]
        point+=m
        # A=np.sort(A)
    else:
        break

print(np.sum(A))
    
#     for j in range (B):
#         count=np.count_nonzero(A<C)
#         if count>0:
#             m=min(B,count)
#             A[:m]=C
#         else:
#             continue
    
#     A=np.sort(A)

# print(np.sum(A)) import numpy as np numpy N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M A=np.array(list(map(int,input().split())),dtype=np.int32) A np.array(list(map(int,input().split())),dtype=np.int32) np.array np array list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split dtype=np.int32 dtype np.int32 np int32 A=np.sort(A) A np.sort(A) np.sort np sort A EXC=[] EXC [] for i in range(M):
    exc=list(map(int,input().split()))
    EXC.append(exc) i range(M) range M exc=list(map(int,input().split())) exc list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split EXC.append(exc) EXC.append EXC append exc excArry=np.array(EXC,dtype=np.int32) excArry np.array(EXC,dtype=np.int32) np.array np array EXC dtype=np.int32 dtype np.int32 np int32 col_num=1 col_num 1 Arr=excArry[np.argsort(excArry[:,col_num])[::-1]] Arr excArry[np.argsort(excArry[:,col_num])[::-1]] excArry np.argsort(excArry[:,col_num])[::-1] np.argsort(excArry[:,col_num]) np.argsort np argsort excArry[:,col_num] excArry : ::-1 -1 point=0 point 0 for j in range (M):
    # change_Num=Arr[j][1]
    count=np.count_nonzero(A<Arr[j][1])
    if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=Arr[j][1]
        point+=m
        # A=np.sort(A)
    else:
        break j range (M) range M count=np.count_nonzero(A<Arr[j][1]) count np.count_nonzero(A<Arr[j][1]) np.count_nonzero np count_nonzero A<Arr[j][1] A Arr[j][1] [j] Arr j 1 if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=Arr[j][1]
        point+=m
        # A=np.sort(A)
    else:
        break count > 0 count 0 m=min(count,Arr[j][0]) m min(count,Arr[j][0]) min count Arr[j][0] [j] Arr j 0 A[point:point+m]=Arr[j][1] A[point:point+m] A point:point+m point point+m point m Arr[j][1] [j] Arr j 1 point+=m point m break print(np.sum(A)) print np.sum(A) np.sum np sum A M=map(int,input().split()) map(int,input().split()) M col_num=1 1 col_num N,M=map(int,input().split()) map(int,input().split()) N A=np.sort(A) np.sort(A) A A=np.array(list(map(int,input().split())),dtype=np.int32) np.array(list(map(int,input().split())),dtype=np.int32) A point+=m m point EXC=[] [] EXC excArry=np.array(EXC,dtype=np.int32) np.array(EXC,dtype=np.int32) excArry Arr=excArry[np.argsort(excArry[:,col_num])[::-1]] excArry[np.argsort(excArry[:,col_num])[::-1]] Arr point=0 0 point m=min(count,Arr[j][0]) min(count,Arr[j][0]) m exc=list(map(int,input().split())) list(map(int,input().split())) exc count=np.count_nonzero(A<Arr[j][1]) np.count_nonzero(A<Arr[j][1]) count
import numpy as np


N,M=map(int,input().split())
# A=np.array(list(map(int,input().split())))
A=np.array(list(map(int,input().split())),dtype=np.int32)
A=np.sort(A)

EXC=[]

for i in range(M):
    exc=list(map(int,input().split()))
    EXC.append(exc)
excArry=np.array(EXC,dtype=np.int32)

col_num=1
Arr=excArry[np.argsort(excArry[:,col_num])[::-1]]
# print(A)
# print(Arr)

point=0


for j in range (M):
    # change_Num=Arr[j][1]
    count=np.count_nonzero(A<Arr[j][1])
    if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=Arr[j][1]
        point+=m
        # A=np.sort(A)
    else:
        break

print(np.sum(A))
    
#     for j in range (B):
#         count=np.count_nonzero(A<C)
#         if count>0:
#             m=min(B,count)
#             A[:m]=C
#         else:
#             continue
    
#     A=np.sort(A)

# print(np.sum(A))