n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)

res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
 
print(res)

# d = []
# while l and len(d) <= n:
#     bc = l.pop(0)
#     d.extend([bc[1]]*bc[0])
# ret = 0
# for i in range(n):
#     if d and d[0] > a[0]:
#         ret += d.pop(0)
#     else:
#         ret += a.pop(0)
# print(ret) n, m = map(int, input().split()) n 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 a.sort(reverse=True) a.sort a sort reverse=True reverse True list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split l = [list(map(int, input().split())) for i in range(m)] l [list(map(int, input().split())) for i in range(m)] 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 res = 0 res 0 pos_1 = 0 pos_1 0 pos_2 = 0 pos_2 0 for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
  _ range(n) range n if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
  pos_2 == m or a[pos_1] > l[pos_2][1] pos_2 == m pos_2 m a[pos_1] > l[pos_2][1] a[pos_1] a pos_1 l[pos_2][1] [pos_2] l pos_2 1 res += a[pos_1] res a[pos_1] a pos_1 pos_1 += 1 pos_1 1 res += l[pos_2][1] res l[pos_2][1] [pos_2] l pos_2 1 l[pos_2][0] -= 1 l[pos_2][0] [pos_2] l pos_2 0 1 if l[pos_2][0] == 0:
            pos_2 += 1
  l[pos_2][0] == 0 l[pos_2][0] [pos_2] l pos_2 0 0 pos_2 += 1 pos_2 1 print(res) print res res += l[pos_2][1] l[pos_2][1] res m = map(int, input().split()) map(int, input().split()) m pos_2 += 1 1 pos_2 res = 0 0 res pos_2 = 0 0 pos_2 a = list(map(int, input().split())) list(map(int, input().split())) a res += a[pos_1] a[pos_1] res pos_1 = 0 0 pos_1 pos_1 += 1 1 pos_1 n, m = map(int, input().split()) map(int, input().split()) n l = [list(map(int, input().split())) for i in range(m)] [list(map(int, input().split())) for i in range(m)] l
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
l = [list(map(int, input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)

res = 0
pos_1 = 0
pos_2 = 0
for _ in range(n):
    if pos_2 == m or a[pos_1] > l[pos_2][1]:
        res += a[pos_1]
        pos_1 += 1
    else:
        res += l[pos_2][1]
        l[pos_2][0] -= 1
        if l[pos_2][0] == 0:
            pos_2 += 1
 
print(res)

# d = []
# while l and len(d) <= n:
#     bc = l.pop(0)
#     d.extend([bc[1]]*bc[0])
# ret = 0
# for i in range(n):
#     if d and d[0] > a[0]:
#         ret += d.pop(0)
#     else:
#         ret += a.pop(0)
# print(ret)