import sys
import bisect
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
CB = [None] * M
for i in range(M):
    b, c = map(int, sys.stdin.readline().split())
    CB[i] = (c, b)
CB.sort(reverse=True)

i = 0
ans = 0
for c, b in CB:
    x = bisect.bisect_left(A, c, i)
    count = min(x - i, b)
    ans += c * count
    i += count
for j in range(i, N):
    ans += A[j]
print(ans) import sys sys import bisect bisect 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 CB = [None] * M CB [None] * M [None] None M for i in range(M):
    b, c = map(int, sys.stdin.readline().split())
    CB[i] = (c, b) i range(M) range M b, c = map(int, sys.stdin.readline().split()) b map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split c CB[i] = (c, b) CB[i] CB i (c, b) c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True i = 0 i 0 ans = 0 ans 0 for c, b in CB:
    x = bisect.bisect_left(A, c, i)
    count = min(x - i, b)
    ans += c * count
    i += count c b CB x = bisect.bisect_left(A, c, i) x bisect.bisect_left(A, c, i) bisect.bisect_left bisect bisect_left A c i count = min(x - i, b) count min(x - i, b) min x - i x i b ans += c * count ans c * count c count i += count i count for j in range(i, N):
    ans += A[j] j range(i, N) range i N ans += A[j] ans A[j] A j print(ans) print ans c = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) c A = sorted(map(int, input().split())) sorted(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M CB = [None] * M [None] * M CB ans += c * count c * count ans ans += A[j] A[j] ans b, c = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) b N, M = map(int, input().split()) map(int, input().split()) N i = 0 0 i i += count count i count = min(x - i, b) min(x - i, b) count ans = 0 0 ans x = bisect.bisect_left(A, c, i) bisect.bisect_left(A, c, i) x
import sys
import bisect
N, M = map(int, input().split())
A = sorted(map(int, input().split()))
CB = [None] * M
for i in range(M):
    b, c = map(int, sys.stdin.readline().split())
    CB[i] = (c, b)
CB.sort(reverse=True)

i = 0
ans = 0
for c, b in CB:
    x = bisect.bisect_left(A, c, i)
    count = min(x - i, b)
    ans += c * count
    i += count
for j in range(i, N):
    ans += A[j]
print(ans)