import heapq

n, m = list(map(int, input().split()))
cards = list(map(int, input().split()))
cards.sort()

queries = []
for i in range(m):
    q = list(map(int, input().split()))
    queries.append(q)
queries.sort(key=lambda x: x[1])
queries.reverse()

ans = 0
pos = 0
for q in queries:
    b, c = q
    if cards[min(pos+b-1, n-1)] < c:
        # print('a')
        pos = pos + b
        ans += c * (b - max(0, pos-n))
        if pos >= n:
            break
    else:
        for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
        break

if pos < n:
    for j in range(pos, n):
        ans += cards[j]

print(ans)
 import heapq heapq 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 cards = list(map(int, input().split())) cards list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cards.sort() cards.sort cards sort queries = [] queries [] for i in range(m):
    q = list(map(int, input().split()))
    queries.append(q) i range(m) range m q = list(map(int, input().split())) q list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split queries.append(q) queries.append queries append q queries.sort(key=lambda x: x[1]) queries.sort queries sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x queries.reverse() queries.reverse queries reverse ans = 0 ans 0 pos = 0 pos 0 for q in queries:
    b, c = q
    if cards[min(pos+b-1, n-1)] < c:
        # print('a')
        pos = pos + b
        ans += c * (b - max(0, pos-n))
        if pos >= n:
            break
    else:
        for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
        break q queries b, c = q b q c if cards[min(pos+b-1, n-1)] < c:
        # print('a')
        pos = pos + b
        ans += c * (b - max(0, pos-n))
        if pos >= n:
            break
    else:
        for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
        break cards[min(pos+b-1, n-1)] < c cards[min(pos+b-1, n-1)] cards min(pos+b-1, n-1) min pos+b-1 pos+b pos b 1 n-1 n 1 c pos = pos + b pos pos + b pos b ans += c * (b - max(0, pos-n)) ans c * (b - max(0, pos-n)) c b - max(0, pos-n) b max(0, pos-n) max 0 pos-n pos n if pos >= n:
            break
     pos >= n pos n break for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
         i range(b) range b if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
         cards[pos+i] < c cards[pos+i] cards pos+i pos i c ans += c ans c pos += i pos i for j in range(pos, n):
                    ans += cards[j]

                 j range(pos, n) range pos n ans += cards[j] ans cards[j] cards j pos = n pos n break break if pos < n:
    for j in range(pos, n):
        ans += cards[j] pos < n pos n for j in range(pos, n):
        ans += cards[j] j range(pos, n) range pos n ans += cards[j] ans cards[j] cards j print(ans) print ans ans = 0 0 ans b, c = q q b pos = pos + b pos + b pos ans += c * (b - max(0, pos-n)) c * (b - max(0, pos-n)) ans m = list(map(int, input().split())) list(map(int, input().split())) m q = list(map(int, input().split())) list(map(int, input().split())) q pos += i i pos c = q q c pos = n n pos n, m = list(map(int, input().split())) list(map(int, input().split())) n ans += c c ans pos = 0 0 pos ans += cards[j] cards[j] ans queries = [] [] queries ans += cards[j] cards[j] ans cards = list(map(int, input().split())) list(map(int, input().split())) cards
import heapq

n, m = list(map(int, input().split()))
cards = list(map(int, input().split()))
cards.sort()

queries = []
for i in range(m):
    q = list(map(int, input().split()))
    queries.append(q)
queries.sort(key=lambda x: x[1])
queries.reverse()

ans = 0
pos = 0
for q in queries:
    b, c = q
    if cards[min(pos+b-1, n-1)] < c:
        # print('a')
        pos = pos + b
        ans += c * (b - max(0, pos-n))
        if pos >= n:
            break
    else:
        for i in range(b):
            if cards[pos+i] < c:
                # print('b')
                ans += c
            else:
                # print('c')
                pos += i
                for j in range(pos, n):
                    ans += cards[j]

                pos = n
                break
        break

if pos < n:
    for j in range(pos, n):
        ans += cards[j]

print(ans)

