import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
readline = sys.stdin.readline
A = [int(i) for i in readline().split()]

A.sort()

CB = []
for _ in range(m):
    b, c = [int(i) for i in readline().split()]
    CB.append([c, b])
    
CB.sort(reverse=True)

idx = 0
c = 0
for i in range(n):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= m:
        break

print(sum(A)) import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline int(i) for i in readline().split() for i in readline().split() i readline().split() ().split () readline split for i in readline().split() int(i) int i A = [int(i) for i in readline().split()] A [int(i) for i in readline().split()] A.sort() A.sort A sort CB = [] CB [] for _ in range(m):
    b, c = [int(i) for i in readline().split()]
    CB.append([c, b])
     _ range(m) range m int(i) for i in readline().split() for i in readline().split() i readline().split() ().split () readline split for i in readline().split() int(i) int i b, c = [int(i) for i in readline().split()] b [int(i) for i in readline().split()] c CB.append([c, b]) CB.append CB append [c, b] c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True idx = 0 idx 0 c = 0 c 0 for i in range(n):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= m:
        break i range(n) range n if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
     A[i] < CB[idx][0] A[i] A i CB[idx][0] [idx] CB idx 0 A[i] = CB[idx][0] A[i] A i CB[idx][0] [idx] CB idx 0 c += 1 c 1 if CB[idx][1] <= c:
        idx += 1
        c = 0
     CB[idx][1] <= c CB[idx][1] [idx] CB idx 1 c idx += 1 idx 1 c = 0 c 0 if idx >= m:
        break idx >= m idx m break print(sum(A)) print sum(A) sum A n, m = map(int, input().split()) map(int, input().split()) n idx = 0 0 idx c = 0 0 c b, c = [int(i) for i in readline().split()] [int(i) for i in readline().split()] b CB = [] [] CB c += 1 1 c idx += 1 1 idx c = 0 0 c m = map(int, input().split()) map(int, input().split()) m A = [int(i) for i in readline().split()] [int(i) for i in readline().split()] A readline = sys.stdin.readline sys.stdin.readline readline c = [int(i) for i in readline().split()] [int(i) for i in readline().split()] c
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
readline = sys.stdin.readline
A = [int(i) for i in readline().split()]

A.sort()

CB = []
for _ in range(m):
    b, c = [int(i) for i in readline().split()]
    CB.append([c, b])
    
CB.sort(reverse=True)

idx = 0
c = 0
for i in range(n):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= m:
        break

print(sum(A))