n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

pos = 0
for b, c in BC:
    end = (pos + b) if pos + b <= n else n
    for i in range(pos, end):
        if A[i] < c:
            A[i] = c
        else:
            break
    pos = i + 1
    if pos >= n:
        break

print(sum(A)) 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 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 = [list(map(int, input().split())) for _ in range(m)] BC [list(map(int, input().split())) for _ in range(m)] A.sort() A.sort A sort BC.sort(key=lambda x:x[1], reverse=True) BC.sort BC sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True pos = 0 pos 0 for b, c in BC:
    end = (pos + b) if pos + b <= n else n
    for i in range(pos, end):
        if A[i] < c:
            A[i] = c
        else:
            break
    pos = i + 1
    if pos >= n:
        break b c BC end = (pos + b) if pos + b <= n else n end (pos + b) if pos + b <= n else n pos + b <= n pos + b pos b n pos + b pos b n for i in range(pos, end):
        if A[i] < c:
            A[i] = c
        else:
            break
     i range(pos, end) range pos end if A[i] < c:
            A[i] = c
        else:
            break
     A[i] < c A[i] A i c A[i] = c A[i] A i c break pos = i + 1 pos i + 1 i 1 if pos >= n:
        break pos >= n pos n break print(sum(A)) print sum(A) sum A A = list(map(int, input().split())) list(map(int, input().split())) A end = (pos + b) if pos + b <= n else n (pos + b) if pos + b <= n else n end BC = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] BC pos = i + 1 i + 1 pos pos = 0 0 pos m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

pos = 0
for b, c in BC:
    end = (pos + b) if pos + b <= n else n
    for i in range(pos, end):
        if A[i] < c:
            A[i] = c
        else:
            break
    pos = i + 1
    if pos >= n:
        break

print(sum(A))