import bisect
def resolve():
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split(" "))))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ptr = 0
    total = 0
    for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
    total += sum(A[ptr:])
    print(total)

if '__main__' == __name__:
    resolve() import bisect bisect def resolve():
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split(" "))))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ptr = 0
    total = 0
    for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
    total += sum(A[ptr:])
    print(total) resolve 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 = sorted(list(map(int, input().split(" ")))) A sorted(list(map(int, input().split(" ")))) sorted 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 BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True) BC sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True) sorted [list(map(int, input().split())) for _ in range(M)] key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True ptr = 0 ptr 0 total = 0 total 0 for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
     i range(M) range M num, val = BC[i] num BC[i] BC i val _ptr = min(ptr+num, bisect.bisect_left(A, val)) _ptr min(ptr+num, bisect.bisect_left(A, val)) min ptr+num ptr num bisect.bisect_left(A, val) bisect.bisect_left bisect bisect_left A val if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
     _ptr > ptr _ptr ptr total += val*(_ptr-ptr) total val*(_ptr-ptr) val _ptr-ptr _ptr ptr ptr = _ptr ptr _ptr total += sum(A[ptr:]) total sum(A[ptr:]) sum A[ptr:] A ptr: ptr print(total) print total if '__main__' == __name__:
    resolve() '__main__' == __name__ '__main__' __name__ resolve() resolve def resolve():
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split(" "))))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ptr = 0
    total = 0
    for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
    total += sum(A[ptr:])
    print(total) def resolve():
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split(" "))))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ptr = 0
    total = 0
    for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
    total += sum(A[ptr:])
    print(total) resolve
import bisect
def resolve():
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split(" "))))
    BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
    ptr = 0
    total = 0
    for i in range(M):
        num, val = BC[i]
        _ptr = min(ptr+num, bisect.bisect_left(A, val))
        if _ptr > ptr:
            total += val*(_ptr-ptr)
            ptr = _ptr
    total += sum(A[ptr:])
    print(total)

if '__main__' == __name__:
    resolve()