#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc127/tasks/abc127_d
# プライオリティキュー　解説を見ながら実装


import heapq

n, m = map(int, input().strip().split())

q = []
a = list(map(int, input().strip().split()))
for i in range(n):
    heapq.heappush(q,(a[i]*(-1), 1))
for i in range(m):
    b, c = map(int, input().strip().split())
    heapq.heappush(q,(c*(-1), b))

res = 0
for _ in range(n):
    c, b = heapq.heappop(q)
    res += c * (-1)
    if b > 1:
        b -= 1
        heapq.heappush(q, (c, b))

print(res) import heapq heapq n, m = map(int, input().strip().split()) n map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split m q = [] q [] a = list(map(int, input().strip().split())) a list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split for i in range(n):
    heapq.heappush(q,(a[i]*(-1), 1)) i range(n) range n heapq.heappush(q,(a[i]*(-1), 1)) heapq.heappush heapq heappush q (a[i]*(-1), 1) a[i]*(-1) a[i] a i -1 1 for i in range(m):
    b, c = map(int, input().strip().split())
    heapq.heappush(q,(c*(-1), b)) i range(m) range m b, c = map(int, input().strip().split()) b map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split c heapq.heappush(q,(c*(-1), b)) heapq.heappush heapq heappush q (c*(-1), b) c*(-1) c -1 b res = 0 res 0 for _ in range(n):
    c, b = heapq.heappop(q)
    res += c * (-1)
    if b > 1:
        b -= 1
        heapq.heappush(q, (c, b)) _ range(n) range n c, b = heapq.heappop(q) c heapq.heappop(q) heapq.heappop heapq heappop q b res += c * (-1) res c * (-1) c -1 if b > 1:
        b -= 1
        heapq.heappush(q, (c, b)) b > 1 b 1 b -= 1 b 1 heapq.heappush(q, (c, b)) heapq.heappush heapq heappush q (c, b) c b print(res) print res b = heapq.heappop(q) heapq.heappop(q) b b -= 1 1 b m = map(int, input().strip().split()) map(int, input().strip().split()) m b, c = map(int, input().strip().split()) map(int, input().strip().split()) b res += c * (-1) c * (-1) res a = list(map(int, input().strip().split())) list(map(int, input().strip().split())) a res = 0 0 res c, b = heapq.heappop(q) heapq.heappop(q) c n, m = map(int, input().strip().split()) map(int, input().strip().split()) n q = [] [] q c = map(int, input().strip().split()) map(int, input().strip().split()) c
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc127/tasks/abc127_d
# プライオリティキュー　解説を見ながら実装


import heapq

n, m = map(int, input().strip().split())

q = []
a = list(map(int, input().strip().split()))
for i in range(n):
    heapq.heappush(q,(a[i]*(-1), 1))
for i in range(m):
    b, c = map(int, input().strip().split())
    heapq.heappush(q,(c*(-1), b))

res = 0
for _ in range(n):
    c, b = heapq.heappop(q)
    res += c * (-1)
    if b > 1:
        b -= 1
        heapq.heappush(q, (c, b))

print(res)
