import heapq

def main():

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

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

    heapq.heapify(A)

    BC=[]

    for i in range(M):

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

        BC.append(bc)



    BC.sort(reverse=True,key=lambda x:x[1])

    new_BC=[]

    count=0

    for i in range(M):

        for j in range(BC[i][0]):

            new_BC.append(BC[i][1])

            count+=1

            if count==N:

                break

        if count==N:

            break



    flag=False

    for i in range(len(new_BC)):

        a=heapq.heappop(A)

        if a<new_BC[i]:

            heapq.heappush(A,new_BC[i])

        else:

            heapq.heappush(A,a)

            flag=True

        if flag:

            break

    

    print((sum(A)))

if __name__=="__main__":

    main()
def main():

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

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

    A.sort()

    BC=[]

    for i in range(M):

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

        BC.append(bc)



    BC.sort(reverse=True,key=lambda x:x[1])

    new_BC=[]

    count=0

    for i in range(M):

        for j in range(BC[i][0]):

            new_BC.append(BC[i][1])

            count+=1

            if count==N:

                break

        if count==N:

            break



    for i in range(len(new_BC)):

        if A[i]<new_BC[i]:

            A[i]=new_BC[i]

        else:

            break

    

    print((sum(A)))

if __name__=="__main__":

    main()
import heapq


def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    heapq.heapify(A)
    BC = []
    for i in range(M):
        bc = list(map(int, input().split()))
        BC.append(bc)
    BC.sort(reverse=True, key=lambda x: x[1])
    new_BC = []
    count = 0
    for i in range(M):
        for j in range(BC[i][0]):
            new_BC.append(BC[i][1])
            count += 1
            if count == N:
                break
        if count == N:
            break
    flag = False
    for i in range(len(new_BC)):
        a = heapq.heappop(A)
        if a < new_BC[i]:
            heapq.heappush(A, new_BC[i])
        else:
            heapq.heappush(A, a)
            flag = True
        if flag:
            break
    print((sum(A)))


if __name__ == "__main__":
    main()

def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    BC = []
    for i in range(M):
        bc = list(map(int, input().split()))
        BC.append(bc)
    BC.sort(reverse=True, key=lambda x: x[1])
    new_BC = []
    count = 0
    for i in range(M):
        for j in range(BC[i][0]):
            new_BC.append(BC[i][1])
            count += 1
            if count == N:
                break
        if count == N:
            break
    for i in range(len(new_BC)):
        if A[i] < new_BC[i]:
            A[i] = new_BC[i]
        else:
            break
    print((sum(A)))


if __name__ == "__main__":
    main()

-import heapq - - -    heapq.heapify(A) +    A.sort() -    flag = False -        a = heapq.heappop(A) -        if a < new_BC[i]: -            heapq.heappush(A, new_BC[i]) +        if A[i] < new_BC[i]: +            A[i] = new_BC[i] -            heapq.heappush(A, a) -            flag = True -        if flag: