from heapq import heappop, heappush, heapify
def main():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [list(map(int, input().split())) for _ in range(m)]
    heapify(A)
    B.sort(key = lambda x: x[1], reverse = True)
    for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
    print(sum(A))


if __name__ == '__main__':
    main() from heapq import heappop, heappush, heapify def main():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [list(map(int, input().split())) for _ in range(m)]
    heapify(A)
    B.sort(key = lambda x: x[1], reverse = True)
    for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
    print(sum(A)) main n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split B = [list(map(int, input().split())) for _ in range(m)] B [list(map(int, input().split())) for _ in range(m)] heapify(A) heapify A B.sort(key = lambda x: x[1], reverse = True) B.sort B sort key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse = True reverse True for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
     (b, c) b c B if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
     c > A[0] c A[0] A 0 for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
     i range(b) range b a = heappop(A) a heappop(A) heappop A heappush(A, max(a, c)) heappush A max(a, c) max a c print(sum(A)) print sum(A) sum A if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [list(map(int, input().split())) for _ in range(m)]
    heapify(A)
    B.sort(key = lambda x: x[1], reverse = True)
    for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
    print(sum(A)) def main():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [list(map(int, input().split())) for _ in range(m)]
    heapify(A)
    B.sort(key = lambda x: x[1], reverse = True)
    for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
    print(sum(A)) main
from heapq import heappop, heappush, heapify
def main():
    n, m = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = [list(map(int, input().split())) for _ in range(m)]
    heapify(A)
    B.sort(key = lambda x: x[1], reverse = True)
    for (b, c) in B:
        if c > A[0]:
            for i in range(b):
                a = heappop(A)
                heappush(A, max(a, c))
    print(sum(A))


if __name__ == '__main__':
    main()
