def main():
    from heapq import heapify, heappushpop
    _, M = (int(i) for i in input().split())
    A = ([int(i) for i in input().split()])
    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print(sum(A))


if __name__ == '__main__':
    main() def main():
    from heapq import heapify, heappushpop
    _, M = (int(i) for i in input().split())
    A = ([int(i) for i in input().split()])
    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print(sum(A)) main from heapq import heapify, heappushpop int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i _, M = (int(i) for i in input().split()) _ (int(i) for i in input().split()) M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = ([int(i) for i in input().split()]) A [int(i) for i in input().split()] [int(i) for i in input().split()] for j in range(M) for j in range(M) j range(M) range M for j in range(M) [int(i) for i in input().split()] BC = [[int(i) for i in input().split()] for j in range(M)] BC [[int(i) for i in input().split()] for j in range(M)] heapify(A) heapify A BC.sort(lambda p: p[1], reverse=True) BC.sort BC sort lambda p: p[1] p[1] p 1 p reverse=True reverse True for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
     b c BC if A[0] >= c:
            break
         A[0] >= c A[0] A 0 c break for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
     _ range(b) range b if A[0] >= c:
                break
             A[0] >= c A[0] A 0 c break heappushpop(A, c) heappushpop A c print(sum(A)) print sum(A) sum A if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    from heapq import heapify, heappushpop
    _, M = (int(i) for i in input().split())
    A = ([int(i) for i in input().split()])
    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print(sum(A)) def main():
    from heapq import heapify, heappushpop
    _, M = (int(i) for i in input().split())
    A = ([int(i) for i in input().split()])
    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print(sum(A)) main
def main():
    from heapq import heapify, heappushpop
    _, M = (int(i) for i in input().split())
    A = ([int(i) for i in input().split()])
    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print(sum(A))


if __name__ == '__main__':
    main()
