# -*- coding: utf-8 -*-
"""
Created on Fri Jun 19 16:42:06 2020

@author: NEC-PCuser
"""

import heapq

N, M = map(int, input().split())

A = list(map(int, input().split()))

B_C = []
for i in range(M):
    b_c = list(map(int, input().split()))
    B_C.append(b_c)
 
B_C = sorted(B_C, reverse=True, key=lambda x: x[1])
ans = sum(A)
heapq.heapify(A)
i = 0 

while True:
    for j in range(B_C[i][0]):
        c = heapq.heappop(A)
        ans -= c
        if c < B_C[i][1]:
            heapq.heappush(A, B_C[i][1])
            ans += B_C[i][1]
        else:
            heapq.heappush(A, c)
            ans += c
            break
    else:
        i += 1
        if (len(B_C) == i):
            break
        continue
    break

print(ans) """
Created on Fri Jun 19 16:42:06 2020

@author: NEC-PCuser
""" import heapq heapq 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 B_C = [] B_C [] for i in range(M):
    b_c = list(map(int, input().split()))
    B_C.append(b_c)
  i range(M) range M b_c = list(map(int, input().split())) b_c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split B_C.append(b_c) B_C.append B_C append b_c B_C = sorted(B_C, reverse=True, key=lambda x: x[1]) B_C sorted(B_C, reverse=True, key=lambda x: x[1]) sorted B_C reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x ans = sum(A) ans sum(A) sum A heapq.heapify(A) heapq.heapify heapq heapify A i = 0 i 0 while True:
    for j in range(B_C[i][0]):
        c = heapq.heappop(A)
        ans -= c
        if c < B_C[i][1]:
            heapq.heappush(A, B_C[i][1])
            ans += B_C[i][1]
        else:
            heapq.heappush(A, c)
            ans += c
            break
    else:
        i += 1
        if (len(B_C) == i):
            break
        continue
    break True for j in range(B_C[i][0]):
        c = heapq.heappop(A)
        ans -= c
        if c < B_C[i][1]:
            heapq.heappush(A, B_C[i][1])
            ans += B_C[i][1]
        else:
            heapq.heappush(A, c)
            ans += c
            break
    else:
        i += 1
        if (len(B_C) == i):
            break
        continue
     j range(B_C[i][0]) range B_C[i][0] [i] B_C i 0 c = heapq.heappop(A) c heapq.heappop(A) heapq.heappop heapq heappop A ans -= c ans c if c < B_C[i][1]:
            heapq.heappush(A, B_C[i][1])
            ans += B_C[i][1]
        else:
            heapq.heappush(A, c)
            ans += c
            break
     c < B_C[i][1] c B_C[i][1] [i] B_C i 1 heapq.heappush(A, B_C[i][1]) heapq.heappush heapq heappush A B_C[i][1] [i] B_C i 1 ans += B_C[i][1] ans B_C[i][1] [i] B_C i 1 heapq.heappush(A, c) heapq.heappush heapq heappush A c ans += c ans c break i += 1 i 1 if (len(B_C) == i):
            break
         len(B_C) == i len(B_C) len B_C i break continue break print(ans) print ans A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M ans = sum(A) sum(A) ans B_C = sorted(B_C, reverse=True, key=lambda x: x[1]) sorted(B_C, reverse=True, key=lambda x: x[1]) B_C ans -= c c ans ans += B_C[i][1] B_C[i][1] ans ans += c c ans N, M = map(int, input().split()) map(int, input().split()) N i += 1 1 i b_c = list(map(int, input().split())) list(map(int, input().split())) b_c B_C = [] [] B_C i = 0 0 i c = heapq.heappop(A) heapq.heappop(A) c
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 19 16:42:06 2020

@author: NEC-PCuser
"""

import heapq

N, M = map(int, input().split())

A = list(map(int, input().split()))

B_C = []
for i in range(M):
    b_c = list(map(int, input().split()))
    B_C.append(b_c)
 
B_C = sorted(B_C, reverse=True, key=lambda x: x[1])
ans = sum(A)
heapq.heapify(A)
i = 0 

while True:
    for j in range(B_C[i][0]):
        c = heapq.heappop(A)
        ans -= c
        if c < B_C[i][1]:
            heapq.heappush(A, B_C[i][1])
            ans += B_C[i][1]
        else:
            heapq.heappush(A, c)
            ans += c
            break
    else:
        i += 1
        if (len(B_C) == i):
            break
        continue
    break

print(ans)
