N, M = map(int, input().split())
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
    b, c = map(int, input().split())
    L.append([b, c])
L.sort(key=lambda x: x[1], reverse=True)
# 変更前のカードの枚数
# 変更後のカードの枚数
# をそれぞれ保存しておく

idx = 0
for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break
print(sum(A)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(map(int, input().split())) A sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split L = [] L [] for _ in range(M):
    b, c = map(int, input().split())
    L.append([b, c]) _ range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c L.append([b, c]) L.append L append [b, c] b c L.sort(key=lambda x: x[1], reverse=True) L.sort L sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True idx = 0 idx 0 for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break i range(N) range N if (idx > len(L) - 1):
        break
     idx > len(L) - 1 idx len(L) - 1 len(L) len L 1 break if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break A[i] < L[idx][1] A[i] A i L[idx][1] [idx] L idx 1 A[i] = L[idx][1] A[i] A i L[idx][1] [idx] L idx 1 L[idx][0] -= 1 L[idx][0] [idx] L idx 0 1 if (L[idx][0] != 0):
            continue
        else:
            idx += 1
     L[idx][0] != 0 L[idx][0] [idx] L idx 0 0 continue idx += 1 idx 1 break print(sum(A)) print sum(A) sum A b, c = map(int, input().split()) map(int, input().split()) b M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N A = sorted(map(int, input().split())) sorted(map(int, input().split())) A c = map(int, input().split()) map(int, input().split()) c idx += 1 1 idx idx = 0 0 idx L = [] [] L
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
    b, c = map(int, input().split())
    L.append([b, c])
L.sort(key=lambda x: x[1], reverse=True)
# 変更前のカードの枚数
# 変更後のカードの枚数
# をそれぞれ保存しておく

idx = 0
for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break
print(sum(A))
