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

A=list(map(int,input().split()))

CB=[[0,0] for _ in range(M)]



for i in range(M):

    CB[i][1],CB[i][0]=list(map(int,input().split()))

    

A.sort()

CB.sort(reverse=True)



#Aを小さい順に見る，Cが大きい順に変更操作をして確定していく

cc=0

ans=0

for i in range(N):

    if cc<M:

        if A[i]<CB[cc][0]:

            A[i]=CB[cc][0]

            CB[cc][1]-=1

            if CB[cc][1]==0:

                cc+=1

    ans+=A[i]

        

print(ans)
import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    CB=[[0,0]for _ in range(M)]

    A.sort()

    for i in range(M):

        CB[i][1],CB[i][0]=MI()

        

    CB.sort(reverse=True)

    now=0

    

    for i in range(N):

        if CB[now][1]<=0:

            now+=1

        

        if now>=M:

            break    

        

        ch=CB[now][0]

        if A[i]<ch:

            A[i]=ch

            CB[now][1]-=1

        else:

            break

        

    print((sum(A)))

    



main()

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
CB = [[0, 0] for _ in range(M)]
for i in range(M):
    CB[i][1], CB[i][0] = list(map(int, input().split()))
A.sort()
CB.sort(reverse=True)
# Aを小さい順に見る，Cが大きい順に変更操作をして確定していく
cc = 0
ans = 0
for i in range(N):
    if cc < M:
        if A[i] < CB[cc][0]:
            A[i] = CB[cc][0]
            CB[cc][1] -= 1
            if CB[cc][1] == 0:
                cc += 1
    ans += A[i]
print(ans)

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    CB = [[0, 0] for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1], CB[i][0] = MI()
    CB.sort(reverse=True)
    now = 0
    for i in range(N):
        if CB[now][1] <= 0:
            now += 1
        if now >= M:
            break
        ch = CB[now][0]
        if A[i] < ch:
            A[i] = ch
            CB[now][1] -= 1
        else:
            break
    print((sum(A)))


main()

-N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -CB = [[0, 0] for _ in range(M)] -for i in range(M): -    CB[i][1], CB[i][0] = list(map(int, input().split())) -A.sort() -CB.sort(reverse=True) -# Aを小さい順に見る，Cが大きい順に変更操作をして確定していく -cc = 0 -ans = 0 -for i in range(N): -    if cc < M: -        if A[i] < CB[cc][0]: -            A[i] = CB[cc][0] -            CB[cc][1] -= 1 -            if CB[cc][1] == 0: -                cc += 1 -    ans += A[i] -print(ans) +import sys + +input = sys.stdin.readline + + +def I(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def main(): +    mod = 10**9 + 7 +    N, M = MI() +    A = LI() +    CB = [[0, 0] for _ in range(M)] +    A.sort() +    for i in range(M): +        CB[i][1], CB[i][0] = MI() +    CB.sort(reverse=True) +    now = 0 +    for i in range(N): +        if CB[now][1] <= 0: +            now += 1 +        if now >= M: +            break +        ch = CB[now][0] +        if A[i] < ch: +            A[i] = ch +            CB[now][1] -= 1 +        else: +            break +    print((sum(A))) + + +main()