import sys
import heapq


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    heapq.heapify(L)
    for a in A:
        heapq.heappush(L, (-a, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
    ans = 0
    count = 0
    while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c

if __name__ == "__main__":
    main() import sys sys import heapq heapq def input():
    return sys.stdin.readline().rstrip() input return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    heapq.heapify(L)
    for a in A:
        heapq.heappush(L, (-a, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
    ans = 0
    count = 0
    while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c main N, M = map(int, input().split()) N 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 L = [] L [] heapq.heapify(L) heapq.heapify heapq heapify L for a in A:
        heapq.heappush(L, (-a, 1))

     a A heapq.heappush(L, (-a, 1)) heapq.heappush heapq heappush L (-a, 1) -a a 1 for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
     i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c heapq.heappush(L, (-c, b)) heapq.heappush heapq heappush L (-c, b) -c c b ans = 0 ans 0 count = 0 count 0 while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c True c, b = heapq.heappop(L) c heapq.heappop(L) heapq.heappop heapq heappop L b if count +b >=N:
            print(-ans - c*(N-count))
            exit()
         count +b >=N count +b count b N print(-ans - c*(N-count)) print -ans - c*(N-count) -ans ans c*(N-count) c N-count N count exit() exit count += b count b ans +=b*c ans b*c b c if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    heapq.heapify(L)
    for a in A:
        heapq.heappush(L, (-a, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
    ans = 0
    count = 0
    while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    heapq.heapify(L)
    for a in A:
        heapq.heappush(L, (-a, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
    ans = 0
    count = 0
    while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c main def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input
import sys
import heapq


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    L = []
    heapq.heapify(L)
    for a in A:
        heapq.heappush(L, (-a, 1))

    for i in range(M):
        b, c = map(int, input().split())
        heapq.heappush(L, (-c, b))
    ans = 0
    count = 0
    while True:
        c, b = heapq.heappop(L)
        if count +b >=N:
            print(-ans - c*(N-count))
            exit()
        count += b
        ans +=b*c

if __name__ == "__main__":
    main()
