import sys
input = sys.stdin.readline


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

# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)

tmp = []
# tmpがN個を超えるまで、cをb個足す
for b, c in BC:
    tmp += [c] * b
    if len(tmp) >= N:
        break

# Aとtmpを混ぜてソート
nums = A + tmp
nums.sort(reverse=True)
# 上からN個の総和
print(sum(nums[:N])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 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)] 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 tmp = [] tmp [] for b, c in BC:
    tmp += [c] * b
    if len(tmp) >= N:
        break

# Aとtmpを混ぜてソート b c BC tmp += [c] * b tmp [c] * b [c] c b if len(tmp) >= N:
        break

# Aとtmpを混ぜてソート len(tmp) >= N len(tmp) len tmp N break nums = A + tmp nums A + tmp A tmp nums.sort(reverse=True) nums.sort nums sort reverse=True reverse True print(sum(nums[:N])) print sum(nums[:N]) sum nums[:N] nums :N N input = sys.stdin.readline sys.stdin.readline input A = list(map(int, input().split())) list(map(int, input().split())) A tmp = [] [] tmp nums = A + tmp A + tmp nums N, M = list(map(int, input().split())) list(map(int, input().split())) N tmp += [c] * b [c] * b tmp BC = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] BC M = list(map(int, input().split())) list(map(int, input().split())) M
import sys
input = sys.stdin.readline


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

# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)

tmp = []
# tmpがN個を超えるまで、cをb個足す
for b, c in BC:
    tmp += [c] * b
    if len(tmp) >= N:
        break

# Aとtmpを混ぜてソート
nums = A + tmp
nums.sort(reverse=True)
# 上からN個の総和
print(sum(nums[:N]))
